1uses
2 System.Win.Registry;
3
4type
5 TDelphiInfo = record
6 Name: string;
7 RegKey: string;
8 end;
9
10const
11 AllDelphis: array[0..24] of TDelphiInfo = (
12 (Name: '2'; RegKey: '\SOFTWARE\Borland\Delphi\2.0'),
13 (Name: '3'; RegKey: '\SOFTWARE\Borland\Delphi\3.0'),
14 (Name: '4'; RegKey: '\SOFTWARE\Borland\Delphi\4.0'),
15 (Name: '5'; RegKey: '\SOFTWARE\Borland\Delphi\5.0'),
16 (Name: '6'; RegKey: '\SOFTWARE\Borland\Delphi\6.0'),
17 (Name: '7'; RegKey: '\SOFTWARE\Borland\Delphi\7.0'),
18 (Name: '2005'; RegKey: '\SOFTWARE\Borland\BDS\3.0'),
19 (Name: '2006'; RegKey: '\SOFTWARE\Borland\BDS\4.0'),
20 (Name: '2007'; RegKey: '\SOFTWARE\Borland\BDS\5.0'),
21 (Name: '2009'; RegKey: '\SOFTWARE\CodeGear\BDS\6.0'),
22 (Name: '2010'; RegKey: '\SOFTWARE\CodeGear\BDS\7.0'),
23 (Name: 'XE'; RegKey: '\Software\Embarcadero\BDS\8.0'),
24 (Name: 'XE2'; RegKey: '\Software\Embarcadero\BDS\9.0'),
25 (Name: 'XE3'; RegKey: '\Software\Embarcadero\BDS\10.0'),
26 (Name: 'XE4'; RegKey: '\Software\Embarcadero\BDS\11.0'),
27 (Name: 'XE5'; RegKey: '\Software\Embarcadero\BDS\12.0'),
28 (Name: 'XE6'; RegKey: '\Software\Embarcadero\BDS\14.0'),
29 (Name: 'XE7'; RegKey: '\Software\Embarcadero\BDS\15.0'),
30 (Name: 'XE8'; RegKey: '\Software\Embarcadero\BDS\16.0'),
31 (Name: '10 Seattle'; RegKey: '\Software\Embarcadero\BDS\17.0'),
32 (Name: '10.1 Berlin'; RegKey: '\Software\Embarcadero\BDS\18.0'),
33 (Name: '10.2 Tokyo'; RegKey: '\Software\Embarcadero\BDS\19.0'),
34 (Name: '10.3 Rio'; RegKey: '\Software\Embarcadero\BDS\20.0'),
35 (Name: '10.4 Sydney'; RegKey: '\Software\Embarcadero\BDS\21.0'),
36 (Name: '11 Alexandria'; RegKey: '\Software\Embarcadero\BDS\22.0')
37 );
38
39function IsRegisteredInRootKey(RootKey: HKEY; SubKey: string): Boolean;
40begin
41 var Reg: TRegistry := TRegistry.Create(KEY_READ);
42 try
43 Reg.RootKey := RootKey;
44 Result := Reg.OpenKeyReadOnly(SubKey);
45 if Result then
46 Reg.CloseKey;
47 finally
48 Reg.Free;
49 end;
50end;
51
52function IsRegistered(SubKey: string): Boolean;
53begin
54 Result := IsRegisteredInRootKey(HKEY_LOCAL_MACHINE, SubKey);
55 if not Result then
56 Result := IsRegisteredInRootKey(HKEY_CURRENT_USER, SubKey);
57end;
58
59function FindInstallations: TArray<TDelphiInfo>;
60begin
61 SetLength(Result, Length(AllDelphis));
62 var FoundCount: Integer := 0;
63 for var Rec: TDelphiInfo in AllDelphis do
64 begin
65 if IsRegistered(Rec.RegKey) then
66 begin
67 Result[FoundCount] := Rec;
68 Inc(FoundCount);
69 end;
70 end;
71 SetLength(Result, FoundCount);
72end;