Table of Contents
How can I retrieve values from Windows Registry ?
How can I store values into Windows Registry ?
How can I remember the last Path in the File Dialog ?
How can I retrieve values from Windows Registry ?
To do this, you should add Registry in your USES clause. Remember, specify False in OpenKey() method to read, and True to write values.
procedure ReadRegistry;
var
regEntry : TRegistry;
begin
regEntry := TRegistry.Create;
regEntry.RootKey := HKEY_CURRENT_USER;
if regEntry.OpenKey( 'Software\Hianoto', False ) then begin
try
nInteger := regEntry.ReadInteger( 'Integer' );
except
{ Do nothing }
end;
regEntry.CloseKey;
end;
regEntry.Free;
end;
Go Top
How can I store values into Windows Registry ?
Well, as usual, you should add Registry in your USES clause. Don't forget, you should use True in OpenKey() method to write values.
procedure WriteRegistry;
var
regEntry : TRegistry;
begin
regEntry := TRegistry.Create;
regEntry.RootKey := HKEY_CURRENT_USER;
if regEntry.OpenKey( 'Software\Hian', True ) then begin
regEntry.WriteInteger( 'Integer', 1 );
regEntry.WriteString( 'String', 'Hian' );
regEntry.CloseKey;
end;
regEntry.Free;
end;
Go Top
How can I remember the last Path in the File Dialog ?
Actually you can do this by yourself, using the previous tips. However, I'd like to share with you a short code snippet, as follows:
procedure OpenFile;
var
regEntry: TRegistry;
begin
regEntry := TRegistry.Create;
if regEntry.OpenKey( APP_REG_KEY, False ) then begin
try
dlgFileOpen.InitialDir := ReadString( REG_PREFS_DEF_DIR );
except
dlgFileOpen.InitialDir := '';
regEntry.CloseKey;
end;
regEntry.Free;
if dlgFileOpen.Execute then
execOpenFile( dlgFileOpen.FileName );
end;
Go Top