The key to detect the Delphi (or Rad-Studio) installed versions in a system is check the existence of these registry keys under the HKEY_CURRENT_USER root.
UPDATE
Tondrej makes a good comment about to check the existence of the instalation in the HKEY_LOCAL_MACHINE root, so the code has been modified.
for Borland delphi until version 7
\Software\Borland\Delphi\DelphiVersion for example for Delphi 7 must be \Software\Borland\Delphi\7.0
for Borland Delphi 8 to Borland Development Studio 2006
\Software\Borland\BDS\BdsVersion for example for Borland Development Studio 2005 must be \Software\Borland\BDS\2.0
for Codegear Rad Studio 2009 and 2010
\Software\CodeGear\BDS\BdsVersion for example for Rad Studio 2009 must be \Software\CodeGear\BDS\6.0
and finally for Delphi XE
\Software\Embarcadero\BDS\8.0
Now you must check (and read) the existence of the “App” Value wich store the location of the Delphi (or Rad Studio) IDE.
putting all together you can create an structure like this to access the information in the windows registry.
type
TDelphiVersions =
(
Delphi4,
Delphi5,
Delphi6,
Delphi7,
Delphi8,
Delphi2005,
Delphi2006,
Delphi2007,
Delphi2009,
Delphi2010,
DelphiXE
);
const
DelphiVersionsNames: array[TDelphiVersions] of string = (
'Delphi 4',
'Delphi 5',
'Delphi 6',
'Delphi 7',
'Delphi 8',
'BDS 2005',
'BDS 2006',
'RAD Studio 2007',
'RAD Studio 2009',
'RAD Studio 2010',
'RAD Studio XE'
);
DelphiRegPaths: array[TDelphiVersions] of string = (
'\Software\Borland\Delphi\4.0',
'\Software\Borland\Delphi\5.0',
'\Software\Borland\Delphi\6.0',
'\Software\Borland\Delphi\7.0',
'\Software\Borland\BDS\2.0',
'\Software\Borland\BDS\3.0',
'\Software\Borland\BDS\4.0',
'\Software\Borland\BDS\5.0',
'\Software\CodeGear\BDS\6.0',
'\Software\CodeGear\BDS\7.0',
'\Software\Embarcadero\BDS\8.0');
and declaring a couple of helper functions to facilitate the work
function RegKeyExists(const RegPath: string;const RootKey :HKEY): Boolean;
var
Reg: TRegistry;
begin
try
Reg := TRegistry.Create;
try
Reg.RootKey := RootKey;
Result := Reg.KeyExists(RegPath);
finally
Reg.Free;
end;
except
Result := False;
end;
end;
function RegReadStr(const RegPath, RegValue:string; var Str: string;const RootKey :HKEY): Boolean;
var
Reg: TRegistry;
begin
try
Reg := TRegistry.Create;
try
Reg.RootKey := RootKey;
Result := Reg.OpenKey(RegPath, True);
if Result then Str:=Reg.ReadString(RegValue);
finally
Reg.Free;
end;
except
Result := False;
end;
end;
procedure ExtractIconFileToImageList(ImageList: TImageList; const Filename: string);
var
FileInfo: TShFileInfo;
begin
if FileExists(Filename) then
begin
FillChar(FileInfo, SizeOf(FileInfo), 0);
SHGetFileInfo(PChar(Filename), 0, FileInfo, SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON);
if FileInfo.hIcon <> 0 then
begin
ImageList_AddIcon(ImageList.Handle, FileInfo.hIcon);
DestroyIcon(FileInfo.hIcon);
end;
end;
end;
finally we can fill a listview with the result adding a fancy Delphi icon
Var
item : TListItem;
DelphiComp : TDelphiVersions;
FileName : string;
ImageIndex : Integer;
Found : Boolean;
begin
for DelphiComp := Low(TDelphiVersions) to High(TDelphiVersions) do
begin
Found:=RegKeyExists(DelphiRegPaths[DelphiComp],HKEY_CURRENT_USER);
if Found then
Found:=RegReadStr(DelphiRegPaths[DelphiComp],'App',FileName,HKEY_CURRENT_USER) and FileExists(FileName);
if not Found then
begin
Found:=RegKeyExists(DelphiRegPaths[DelphiComp],HKEY_LOCAL_MACHINE);
if Found then
Found:=RegReadStr(DelphiRegPaths[DelphiComp],'App',FileName,HKEY_LOCAL_MACHINE) and FileExists(FileName);
end;
if Found then
begin
item:=ListViewIDEs.Items.Add;
item.Caption:=DelphiVersionsNames[DelphiComp];
item.SubItems.Add(FileName);
ExtractIconFileToImageList(ImageList1,Filename);
ImageIndex :=ImageList1.Count-1;
item.ImageIndex:=ImageIndex;
end;
end;
end;
and the final result will look like this
Download the demo project (Delphi 2007) from here.





















