Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - Delicious Software


Related products
Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#
just4fun

Special
Free Software Promotion
Offers for Resellers

Follow us
Blogspot Twitter

Use registry instead of *.ini file - Registry - Tips & Tricks - Greatis Delphi Pages

Ini files are necessary for a storage of an information and parameters of the programs. It is possible to do it with use a registry.
This example create HKEY_LOCAL_MACHINE\Greatis Software\Example key with "First page" parameter, which stores a path to rtf file. This file will be loading from this parameter after Button2 click event.
You can store boolean, time and others types of variables in registry also.


uses Registry;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
  with TRegistry.Create do
  begin
   LazyWrite:=False;
   RootKey:=HKEY_LOCAL_MACHINE;
   if OpenKey('Greatis Software\Example', True) then
     WriteString('First page', 'c:\overview.rtf')
   else
     MessageDlg('Registry reading error', mtError, [mbOk], 0);
   CloseKey;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with TRegistry.Create do
  begin
    RootKey:=HKEY_LOCAL_MACHINE;
    if OpenKey('Greatis Software\Example', False) then
    try
      RichEdit1.Lines.LoadFromFile(ReadString('First page'));
    except
      MessageDlg('Can not go to handle', mtError, [mbOk], 0);
    end
    else
      MessageDlg('Registry reading error', mtError, [mbOk], 0);
    CloseKey;
  end;
end;
Related chapters
System

Related topics
Detect windows version
Detect font (Small or Large) is in use
Run program not in StartUp Folder

For more
Delphi Help

Download source