Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

TRegIniFile: Windows Registry in Delphi

In this Quick Tips we will create a routine to log information in the Windows registry.

 

Hello everybody! In this "Quick Tips" we will create a routine to log information in the Windows registry.

For this we have the class “TRegIniFile” in Delphi which is in the Registry Unit.

Initially we will create one Unit and save as “uRegister.pas”. We can see below the complete code where we have two methods: SaveRegister (Procedure) and ReadRegister (Function).

 

unit uRegister;

interface

   uses Windows, Registry;

   procedure SaveRegister(xFile, xSection, xIdent, xValue: String);

      function ReadRegister(xFile, xSection, xIdent: String): String;

implementation

{Procedure to create a certain value in registry}

procedure SaveRegister(xFile, xSection, xIdent, xValue: String);

var

   FileReg: TRegIniFile;

begin

   FileReg := TRegIniFile.Create(xFile);

   Try

      FileReg.WriteString(xSection, xIdent, xValue);

   Finally

      FileReg.Free;

   end;

end;

 

{Function to return the contents of a determined registry}

function ReadRegister(xFile, xSection, xIdent: String): String;

var

   FileReg: TRegIniFile;

begin

   FileReg := TRegIniFile.Create(xFile);

   Try

      Result := FileReg.ReadString(xSection, xIdent, '');

   Finally

      FileReg.Free;

   end;

end;

end. 

Now implement the sample using the methods developed in uRegistro.pas. Let's create a form with:
         * 4 TLabeledEdit (EdtContent, EdtFile, EdtSection, EdtIdent);
         * 2 BitBtn (BtnSave, BtnRead).

See the image below:


 

{Implementing the OnClick event of BtnSave}

procedure TFrmPrincipal.BtnSaveClick(Sender: TObject);

begin

    SaveRegister(EdtFile.Text, EdtSection.Text, EdtIdent.Text, EdtContent.Text);

    EdtContent.Clear;

end;

{ Implementing the OnClick event of BtnRead }

procedure TFrmPrincipal.BtnReadClick(Sender: TObject);

begin

    EdtContent.Text := ReadRegister (EdtFile.Text, EdtSection.Text, EdtIdent.Text );

end;

 

Let's see the result directly in the registry. To do this, go to the same through the start menu / run and type regedit.

Finding the key HKEY_CURRENT_USER \ DelphiRegister \ Data


Where can we use this feature?
            We can save the last user logged on, the last date of entry into the system, a serial register to hinder piracy of our software and more.

Until next Quick Tips!

Wesley Y

wyamazack@rwsolution.com.br

 



Graduated in System Analysis, in business development for over six years, where he worked in companies of various segments such as financial, commercial, parking, etc.. He is currently a third-party developer analyst Navy of Brazi...

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login