Skip to content
The Road to Delphi — Delphi, VCL, VCL Styles, UxTheme and WinAPI

Detecting installed Delphi versions.

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 Embarcadero RAD Studio (XE to XE5)

\Software\Embarcadero\BDS\BdsVersion for example for RAD Studio XE2 must be \Software\Embarcadero\BDS\9.0

Now you must check (and read) the existence of the “App” Value  which 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.

[sourcecode language=”delphi” wraplines=”false”]
type
TDelphiVersions =
(
Delphi4,
Delphi5,
Delphi6,
Delphi7,
Delphi8,
Delphi2005,
Delphi2006,
Delphi2007,
Delphi2009,
Delphi2010,
DelphiXE,
DelphiXE2,
DelphiXE3,
DelphiXE4,
DelphiXE5
);

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’,
‘RAD Studio XE2’,
‘RAD Studio XE3’,
‘RAD Studio XE4’,
‘RAD Studio XE5’
);

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’,
‘\Software\Embarcadero\BDS\9.0’,
‘\Software\Embarcadero\BDS\10.0’,
‘\Software\Embarcadero\BDS\11.0’,
‘\Software\Embarcadero\BDS\12.0’
);
[/sourcecode]

and declaring a couple of helper functions to facilitate the work

[sourcecode language=”delphi” wraplines=”false”]
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;
[/sourcecode]

finally we can fill a listview with the result adding a fancy Delphi icon

[sourcecode language=”delphi” wraplines=”false”]
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;
[/sourcecode]

And the final result will look like this

the source code (Delphi 2007) is available on Github.

12 responses

  1. clean and elegant, I like it!! I hope you don’t mind if I use this code in my applications ;)

    1. Dorin, you can use the source code as you wish.

  2. In case you installed Delphi under a different user account there is no registry key in HKEY_CURRENT_USER until the first time you start Delphi – which is when it gets created by copying data from HKEY_LOCAL_MACHINE to the current user’s HKEY_CURRENT_USER registry hive. So more precisely you should look in HKEY_LOCAL_MACHINE to detect if Delphi is installed.

    1. tondrej thanks for you observation, you are right wich sometimes the values to detect the presence of delphi are stored in the HKEY_LOCAL_MACHINE root. but mostly of times is stored in the HKEY_CURRENT_USER root.

      1. No, the registry key is always in HKEY_LOCAL_MACHINE (created by Delphi installer), and the first time you start Delphi under a user account it gets copied to HKEY_CURRENT_USER.

  3. […] This post was mentioned on Twitter by Andreano Lanusse, Adriano Santos and Delphi to Delphi, Rodrigo Ruz. Rodrigo Ruz said: Detecting installed delphi versions.: The key to detect the Delphi (or Rad-Studio) installed versions in a system … http://bit.ly/aCU3Iw […]

  4. wow … very useful thanks :)

  5. tondrej :

    No, the registry key is always in HKEY_LOCAL_MACHINE (created by Delphi installer), and the first time you start Delphi under a user account it gets copied to HKEY_CURRENT_USER.

    tondrej, I think the best is to check in both roots (HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER), to be sure.

  6. PresleyDias Avatar
    PresleyDias

    hello,
    i have used http://theroadtodelphi.wordpress.com/2010/10/27/detecting-installed-delphi-versions/ source in my application which i intend to make it available online.
    please tell me how to link you [with your permission] in the attribution license?

    1. Just put a link in the souce code to the original article.

      1. PresleyDias Avatar
        PresleyDias

        ok sure. Thank you

  7. The started edition (XE7) does not seem to have an “App” entry in the registry. I needed to change my script as follows:

    function HasDelphiVersion(const sRegPath: string): Boolean;
    var
    sFileName : string;
    begin
    // From code at https://theroadtodelphi.wordpress.com/2010/10/27/detecting-installed-delphi-versions/

    Result := RegKeyExists( HKEY_CURRENT_USER, sRegPath );
    if Result then
    Result := RegQueryStringValue( HKEY_CURRENT_USER, sRegPath, ‘App’, sFileName ) and FileExists( sFileName );

    // Starter edition may not have “App” registry value
    if not Result then
    Result := RegQueryStringValue( HKEY_CURRENT_USER, sRegPath, ‘RootDir’, sFileName ) and FileExists( sFileName + ‘bin\bds.exe’ );

    if not Result then
    begin
    Result := RegKeyExists( HKEY_LOCAL_MACHINE, sRegPath );
    if Result then
    Result := RegQueryStringValue( HKEY_LOCAL_MACHINE, sRegPath, ‘App’, sFileName ) and FileExists( sFileName );
    end;
    end;

Leave a Reply