Hi Alaa Mukhtar,
ctl32_Registry is a much easier class to use. Call SetValue(cName, uValue) to save a value to the Registry. cName can include a complete path under the current “hive” (the default is HKEY_CURRENT_USER), such as “Software\FoxRockX\NameOfValue”, or can be
just the value name if you’ve set the RegistrySubkey property to the subkey to write to. For example, this code:
loReg.SetValue('Software\FoxRockX\String', 'This is a string')
does the same as this:
loReg.RegistrySubkey = 'Software\FoxRockX' loReg.SetValue('String', 'This is a string')
To specify a different hive, set RegistryKey to the name of the hive, such as “HKEY_LOCAL_MACHINE.” Note than in Windows Vista and later, HKEY_LOCAL_MACHINE is a protected resource and writes to it are actually redirected to a different location.
SetValue can handle more than just strings, which is another benefit over the FFC class. The following works just fine:
loReg.SetValue('DateTime', datetime()) loReg.SetValue('Logical', .T.)
To read a value from the Registry, use GetValue(cName, uDefaultValue). uDefaultValue is the value to return if the key doesn’t exist, but GetValue also uses its data type to determine how to cast the value it reads from the Registry. For example, here’s how
to read the values saved in the previous examples:
lcValue = loReg.GetValue('String', '') ldValue = loReg.GetValue('Date', {/}) ltValue = loReg.GetValue('DateTime', {/:}) llValue = loReg.GetValue('Logical', .F.)
GetValues and SetValues are interesting methods: pass them a reference to a container object, such as a Form or Page in a PageFrame, and the subkey to use, and they read from and write to the Registry the Value property of every control in the container. This
is a fast way to save and restore the contents of the controls in a form.
If you want to determine if a key exists, call SeekValue(cName); it returns .T. if the key can be found.
DeleteValue(cName) deletes the specified value in the Registry. DeleteSubkey(cSubkey) deletes the specified subkey. However, it doesn’t delete the subkey if it contains any subkeys; for that, use DeleteSubkeyTree(cSubkey).
Registry.PRG in the source code for this document demonstrates the use of ctl32_Registry.
The one shortcoming of ctl32_Registry is that it doesn’t support enumerating keys.
Best regards,
Youjun Tang
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.