1uses
2 System.Win.Registry;
3
4type
5 TDelphiInfo = record
6 Name: string;
7 RegKey: string;
8 end;
9
10const
11 AllDelphis: array[0..25] 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 (Name: '12 Athens'; RegKey: '\Software\Embarcadero\BDS\23.0')
38 );
39
40function IsRegisteredInRootKey(RootKey: HKEY; SubKey: string): Boolean;
41begin
42 var Reg: TRegistry := TRegistry.Create(KEY_READ);
43 try
44 Reg.RootKey := RootKey;
45 Result := Reg.OpenKeyReadOnly(SubKey);
46 if Result then
47 Reg.CloseKey;
48 finally
49 Reg.Free;
50 end;
51end;
52
53function IsRegistered(SubKey: string): Boolean;
54begin
55 Result := IsRegisteredInRootKey(HKEY_LOCAL_MACHINE, SubKey);
56 if not Result then
57 Result := IsRegisteredInRootKey(HKEY_CURRENT_USER, SubKey);
58end;
59
60function FindInstallations: TArray<TDelphiInfo>;
61begin
62 SetLength(Result, Length(AllDelphis));
63 var FoundCount: Integer := 0;
64 for var Rec: TDelphiInfo in AllDelphis do
65 begin
66 if IsRegistered(Rec.RegKey) then
67 begin
68 Result[FoundCount] := Rec;
69 Inc(FoundCount);
70 end;
71 end;
72 SetLength(Result, FoundCount);
73end;