Saving and Retrieving Boolean Value from Windows Registry

  

I’m attempting to save/retrieve a Boolean value from the Windows Registry using Delphi Rio (Firemonkey). No matter which state I save, true or false, the code always returns a true value. Here is a sample project that illustrates my method:

uses
System.IniFiles, System.Win.Registry;

const
AppRegKey = ‘Software\Mycroft\TestApp’;

procedure TForm2.btnReadClick(Sender: TObject);
var
Reg: TCustomIniFile;
checked: boolean;
begin
Reg := TRegistryIniFile.Create(”);
checked := False;
if Reg.SectionExists(AppRegKey + ‘\State\BoxChecked’) then begin
checked := Reg.ReadBool(AppRegKey,’Show’, True);
end;
if checked then
ShowMessage(‘Checked’)
else
ShowMessage(‘Unchecked’);
end;

procedure TForm2.btnSaveClick(Sender: TObject);
var
Reg: TCustomIniFile;

begin
Reg := TRegistryIniFile.Create(”);
Reg.WriteBool(AppRegKey + ‘\State\BoxChecked’, ‘Show’, chkBrandNew.IsChecked);
end;

It appears the value is being updated in the Registry, so I’m not sure why it always returns a True value. Can someone please point me in the proper direction?

Comments are closed.