I am having one Delphi XE2 Project to check one Hexadecimal Value from Registry Key MyCompanyName\1. If the Hexadecimal Value is 13, then some message will be there else some other message will be there.
So I have defined the following codes:
procedure TMainForm.BitBtn01Click(Sender: TObject);
var
RegistryEntry : TRegistry;
begin
RegistryEntry := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
RegistryEntry.RootKey := HKEY_LOCAL_MACHINE;
if (RegistryEntry.KeyExists('SOFTWARE\MyCompanyName\1\')) then
begin
if (RegistryEntry.OpenKey('SOFTWARE\MyCompanyName\1\',true)) then
begin
if (RegistryEntry.ReadString('SettingValue') = '0x00000013') then
begin
Memo01.Lines.Add('SettingHexadeciamlValue exist properly')
end
else
begin
Memo01.Lines.Add('SettingHexadeciamlValue does not exist properly')
end;
end
else
begin
if (RegistryEntry.OpenKey('SOFTWARE\MyCompanyName\1\',false)) then
begin
Memo01.Lines.Add('Unable to read RegistryKey ''MyCompanyName''Exiting.......')
end;
end;
end
else
begin
Memo01.Lines.Add('RegistryKey ''MyCompanyName'' does not exist')
end;
end;
After compilation, when I am running the application AsAdministrator, I am getting error mentioning Invalid data type for 'SettingValue'.
These values are integers, not strings, so you should use ReadInteger
, not ReadString
.
Now, hexadecimal is only a way of presenting an integer to the user, that is, a method of creating a 'textual representation' of the integer. For example, the integer 62 has many different textual representations:
62 (decimal)
LXII (Roman numerals)
3E (hexadecimal)
111110 (binary)
Sextiotvå (Swedish words)
etc.
If you want to display this number in hexadecimal, as the registry editor (regedit.exe
) does, you can use the IntToHex
function, which creates a hexadecimal textual representation of the argument integer. Example:
var
myvalue: integer;
...
myvalue := ReadInteger('SettingValue');
ShowMessage(IntToHex(myvalue, 8));
User contributions licensed under CC BY-SA 3.0