Examples Delphi

Title: Usefull unit to create an (un)installation program
Question: Here is my unit with two simple functions to create and remove the registry keys to find my application in the "Uninstall application"'s list.
Just insert the data you want to show in that list in a variable and add it.
Answer:
Unit InstallFunctions;
Interface
Type
TApplicationInfo =
Record
DisplayName : String; // DisplayName
UnInstallFile : String; // UnInstallFile
DisplayIcon : String; // DisplayIcon
ModifyPath : String; // ModifyPath
ProductID : String; // ProductID
Publisher : String; // Publisher
DisplayVersion : String; // DisplayVersion
Contact : String; // Contact
HelpLink : String; // HelpLink
RegCompany : String; // RegCompany
RegOwner : String; // RegOwner
ReadMe : String; // ReadMe
URLUpdateInfo : String; // URLUpdateInfo
Comments : String; // Comments
End;
Function RemoveApplication( DisplayName : String ) : Boolean;
Function AddApplication( ApplicationInfo : TApplicationInfo ) : Boolean;
Implementation
Uses
Windows, SysUtils, Registry;
Const
ChiaveRegistro = '\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall';
Function RemoveApplication( DisplayName : String ) : Boolean;
Const
Chiavi : Array[ 0..13 ] Of String =
(
'DisplayName', 'Uninstallstring', 'DisplayIcon', 'ModifyPath',
'ProductID', 'Publisher', 'DisplayVersion', 'Contact',
'HelpLink', 'RegCompany', 'RegOwner', 'ReadMe',
'URLUpdateInfo', 'Comments'
);
Var
Reg : TRegistry;
IdX : Integer;
Begin
Result := False;
Reg := TRegistry.Create;
Try
Reg.RootKey := HKEY_LOCAL_MACHINE;
If ( Reg.OpenKey( ChiaveRegistro, False ) ) Then Begin
If ( Reg.KeyExists( DisplayName ) ) Then Begin
If ( Reg.OpenKey( DisplayName, False ) ) Then
For IdX := Low( Chiavi ) To High( Chiavi ) Do
If ( Reg.ValueExists( Chiavi[ IdX ] ) ) Then
Reg.DeleteValue( Chiavi[ IdX ] );
If ( Reg.OpenKey( ChiaveRegistro, False ) ) Then Reg.DeleteKey( DisplayName );
End;
End;
Finally
Reg.Destroy;
End;
End;
Function AddApplication( ApplicationInfo : TApplicationInfo ) : Boolean;
Var
Reg : TRegistry;
Begin
Result := False;
If ( Trim( ApplicationInfo.DisplayName ) = '' ) Then Exit;
If ( ( Trim( ApplicationInfo.UnInstallFile ) = '' ) And ( Trim( ApplicationInfo.ModifyPath ) = '' ) ) Then Exit;
Reg := TRegistry.Create;
Try
Reg.RootKey := HKEY_LOCAL_MACHINE;
If ( Reg.OpenKey( ChiaveRegistro, False ) ) Then Begin
Reg.CreateKey( ApplicationInfo.DisplayName );
If ( Reg.OpenKey( ChiaveRegistro + '\' + ApplicationInfo.DisplayName, False ) ) Then Begin
Reg.WriteString( 'DisplayName', ApplicationInfo.DisplayName );
If ( Trim( ApplicationInfo.UnInstallFile ) '' ) Then
Reg.WriteString( 'Uninstallstring', ApplicationInfo.UnInstallFile );
If ( Trim( ApplicationInfo.DisplayIcon ) '' ) Then
Reg.WriteString( 'DisplayIcon', ApplicationInfo.DisplayIcon );
If ( Trim( ApplicationInfo.ModifyPath ) '' ) Then
Reg.WriteString( 'ModifyPath', ApplicationInfo.ModifyPath );
If ( Trim( ApplicationInfo.ProductID ) '' ) Then
Reg.WriteString( 'ProductID', ApplicationInfo.ProductID );
If ( Trim( ApplicationInfo.Publisher ) '' ) Then
Reg.WriteString( 'Publisher', ApplicationInfo.Publisher );
If ( Trim( ApplicationInfo.DisplayVersion ) '' ) Then
Reg.WriteString( 'DisplayVersion', ApplicationInfo.DisplayVersion );
If ( Trim( ApplicationInfo.Contact ) '' ) Then
Reg.WriteString( 'Contact', ApplicationInfo.Contact );
If ( Trim( ApplicationInfo.HelpLink ) '' ) Then
Reg.WriteString( 'HelpLink', ApplicationInfo.HelpLink );
If ( Trim( ApplicationInfo.RegCompany ) '' ) Then
Reg.WriteString( 'RegCompany', ApplicationInfo.RegCompany );
If ( Trim( ApplicationInfo.RegOwner ) '' ) Then
Reg.WriteString( 'RegOwner', ApplicationInfo.RegOwner );
If ( Trim( ApplicationInfo.ReadMe ) '' ) Then
Reg.WriteString( 'ReadMe', ApplicationInfo.ReadMe );
If ( Trim( ApplicationInfo.URLUpdateInfo ) '' ) Then
Reg.WriteString( 'URLUpdateInfo', ApplicationInfo.URLUpdateInfo );
If ( Trim( ApplicationInfo.Comments ) '' ) Then
Reg.WriteString( 'Comments', ApplicationInfo.Comments );
Result := True;
End;
End;
Finally
Reg.Destroy;
End;
End;
End.