uses
System.Win.Registry;
type
TDelphiInfo = record
Name: string;
RegKey: string;
end;
const
AllDelphis: array[0..26] of TDelphiInfo = (
(Name: '2'; RegKey: '\SOFTWARE\Borland\Delphi\2.0'),
(Name: '3'; RegKey: '\SOFTWARE\Borland\Delphi\3.0'),
(Name: '4'; RegKey: '\SOFTWARE\Borland\Delphi\4.0'),
(Name: '5'; RegKey: '\SOFTWARE\Borland\Delphi\5.0'),
(Name: '6'; RegKey: '\SOFTWARE\Borland\Delphi\6.0'),
(Name: '7'; RegKey: '\SOFTWARE\Borland\Delphi\7.0'),
(Name: '2005'; RegKey: '\SOFTWARE\Borland\BDS\3.0'),
(Name: '2006'; RegKey: '\SOFTWARE\Borland\BDS\4.0'),
(Name: '2007'; RegKey: '\SOFTWARE\Borland\BDS\5.0'),
(Name: '2009'; RegKey: '\SOFTWARE\CodeGear\BDS\6.0'),
(Name: '2010'; RegKey: '\SOFTWARE\CodeGear\BDS\7.0'),
(Name: 'XE'; RegKey: '\Software\Embarcadero\BDS\8.0'),
(Name: 'XE2'; RegKey: '\Software\Embarcadero\BDS\9.0'),
(Name: 'XE3'; RegKey: '\Software\Embarcadero\BDS\10.0'),
(Name: 'XE4'; RegKey: '\Software\Embarcadero\BDS\11.0'),
(Name: 'XE5'; RegKey: '\Software\Embarcadero\BDS\12.0'),
(Name: 'XE6'; RegKey: '\Software\Embarcadero\BDS\14.0'),
(Name: 'XE7'; RegKey: '\Software\Embarcadero\BDS\15.0'),
(Name: 'XE8'; RegKey: '\Software\Embarcadero\BDS\16.0'),
(Name: '10 Seattle'; RegKey: '\Software\Embarcadero\BDS\17.0'),
(Name: '10.1 Berlin'; RegKey: '\Software\Embarcadero\BDS\18.0'),
(Name: '10.2 Tokyo'; RegKey: '\Software\Embarcadero\BDS\19.0'),
(Name: '10.3 Rio'; RegKey: '\Software\Embarcadero\BDS\20.0'),
(Name: '10.4 Sydney'; RegKey: '\Software\Embarcadero\BDS\21.0'),
(Name: '11 Alexandria'; RegKey: '\Software\Embarcadero\BDS\22.0'),
(Name: '12 Athens'; RegKey: '\Software\Embarcadero\BDS\23.0'),
(Name: '13 Florence'; RegKey: '\Software\Embarcadero\BDS\37.0')
);
function IsRegisteredInRootKey(RootKey: HKEY; SubKey: string): Boolean;
begin
var Reg: TRegistry := TRegistry.Create(KEY_READ);
try
Reg.RootKey := RootKey;
Result := Reg.OpenKeyReadOnly(SubKey);
if Result then
Reg.CloseKey;
finally
Reg.Free;
end;
end;
function IsRegistered(SubKey: string): Boolean;
begin
Result := IsRegisteredInRootKey(HKEY_LOCAL_MACHINE, SubKey);
if not Result then
Result := IsRegisteredInRootKey(HKEY_CURRENT_USER, SubKey);
end;
function FindInstallations: TArray<TDelphiInfo>;
begin
SetLength(Result, Length(AllDelphis));
var FoundCount: Integer := 0;
for var Rec: TDelphiInfo in AllDelphis do
begin
if IsRegistered(Rec.RegKey) then
begin
Result[FoundCount] := Rec;
Inc(FoundCount);
end;
end;
SetLength(Result, FoundCount);
end;