Class for storing application Info in registry

Quick tutorial showing how to store info about your application in the windows registry. The class is written so that all applications you ever write will get their info stored, this can be useful when writing lots of applications

The reson i wrote this small class is that i tend to write lots of software. This class provides a standard way to store info about an application that can be read by any of your apps.





unit AppRegInfo;



interface

Uses Classes, Sysutils, Registry, Windows;

type

  TApplicationRegistryInfo = class (TObject)

  private

    FAppName: string;

    FLocation: string;

    FVersion: string;

  public

    procedure WriteToRegistry;

    property AppName: string read FAppName write FAppName;

    property Location: string read FLocation write FLocation;

    property Version: string read FVersion write FVersion;

  end;





implementation



procedure TApplicationRegistryInfo.WriteToRegistry;

var

  reg: TRegistry;

begin

  reg := Tregistry.Create;

  try

    reg.RootKey := HKEY_LOCAL_MACHINE;



    if FAppName <> '' then begin


        if reg.OpenKey(Format('\SOFTWARE\Innovative Software\%s\Info',[AppName]),TRUE) then

        begin

            Reg.WriteString('Location',Location);

            Reg.WriteString('Version',Version);

            Reg.WriteDateTime('LastUsed',Now);

        end;

    end;

  finally

    reg.free;

  end;

end;





end.





Even though there are only a few fields in this class, it can easily be extended to suit your needs, consider this class a baseclass that can be extended as needed.



Example Code:



add AppRegInfo to uses in main form.





// register usage first

  reginfo:=TApplicationRegistryInfo.Create;

  try

    reginfo.AppName := 'Application Name';

    reginfo.Location := Application.ExeName;

    // version info this could also be extracted from the exe

    reginfo.Version := '1 Beta';

    reginfo.WriteToRegistry;

  finally

    reginfo.Free;

  end;


 

Share this article!

Follow us!

Find more helpful articles: