Re:Registry-Newbie - Accessing it, and using it instead of WIN.INI
Torje R?rvik <to...@sn.no> wrote in article <320F09E3.6...@sn.no>...
Quote
> * I have managed to insert the working path of my program by
> adding the key: HKEY_CURRENT_USER\Software\MyTinyApp\StartUp
> with the value WorkPath='c:\Program Files\MyTinyApp\' with the help
> of InstallShield Delphi 2.0 Edition.
> But how can I access this information from my application?
uses
Registry;
var
TheReg: TRegistry;
KeyName: String;
ValueStr: String;
begin
TheReg := TRegistry.Create;
try
TheReg.RootKey := HKEY_CURRENT_USER;
KeyName := 'Software\MyTinyApp\StartUp;
if TheReg.OpenKey(KeyName, False) then
begin
ValueStr := TheReg.ReadString('WorkPath');
TheReg.CloseKey;
end;
finally
TheReg.Free;
end;
end;
Also note, the correct place to store the path to your application's EXE under
the Win95 registry is in:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
Paths\MYAPP.EXE
Store the complete path to your app as the default value under that key.
Regstr.pas defines a constant for this path up through ...\App Paths\ as
REGSTR_PATH_APPPATHS.
Storing the path to your application's EXE here will allow a user to simply
type MYAPP (or whatever its name is) in Start|Run on the taskbar and your
application will launch. Here's an example of how to create it:
uses
Registry, Regstr;
var
TheReg: TRegistry;
KeyName: String;
begin
TheReg := TRegistry.Create;
try
{Check AppPath setting, update if necessary}
TheReg.RootKey := HKEY_LOCAL_MACHINE;
KeyName := REGSTR_PATH_APPPATHS + ExtractFileName(Application.ExeName);
if TheReg.OpenKey(KeyName, True) then
begin
if CompareText(TheReg.ReadString(''), Application.ExeName) <> 0 then
TheReg.WriteString('', Application.ExeName);
TheReg.CloseKey;
end;
finally
TheReg.Free;
end;
end;
Mark