Author: Jonas Bilinkevicius
Does anybody know how to get a list of all registered typelibs (like the list in
the typelib import window in Delphi)? I found a place in the registry
(HKCR\TypeLib\...) but a lot of libs are listed more then one time (up to 4 or 5
times) in that place. Do I have to grab all libs from this place? I have found no
API (like EnumTypeLibs) that does this.
Answer:
1 procedure EnumTypeLibs(TypeLibNames: TStringList);
2 var
3 f: TRegistry;
4 keyNames, keyVersions, keyInfos: TStringList;
5 keyName, keyVersion, keyInfo, tlName: string;
6 i, j, k: Integer;
7 begin
8 TypeLibNames.Clear;
9 {TypeLibNames.Sorted := True;}
10 keyNames := nil;
11 keyVersions := nil;
12 keyInfos := nil;
13 f := TRegistry.Create;
14 try
15 keyNames := TStringList.Create;
16 keyVersions := TStringList.Create;
17 keyInfos := TStringList.Create;
18 f.RootKey := HKEY_CLASSES_ROOT;
19 if not f.OpenKey('TypeLib', False) then
20 raise Exception.Create('TRegistry.Open');
21 f.GetKeyNames(keyNames);
22 f.CloseKey;
23 for i := 0 to keyNames.Count - 1 do
24 begin
25 keyName := keyNames.Strings[i];
26 if not f.OpenKey(Format('TypeLib\%s', [keyName]), False) then
27 Continue;
28 f.GetKeyNames(keyVersions);
29 f.CloseKey;
30 for j := 0 to keyVersions.Count - 1 do
31 begin
32 keyVersion := keyVersions.Strings[j];
33 if not f.OpenKey(Format('TypeLib\%s\%s', [keyName, keyVersion]), False) then
34 Continue;
35 tlName := f.ReadString('');
36 f.GetKeyNames(keyInfos);
37 f.CloseKey;
38 for k := 0 to keyInfos.Count - 1 do
39 begin
40 keyInfo := keyInfos.Strings[k];
41 {$B-}
42 if (keyInfo = '') or (keyInfo[1] < '0') or (keyInfo[1] > '9') then
43 Continue;
44 if not f.OpenKey(Format('TypeLib\%s\%s\%s\win32', [keyName, keyVersion,
45 keyInfo]), False) then
46 Continue;
47 f.CloseKey;
48 TypeLibNames.Add(Format('%s ver.%s', [tlName, keyVersion]));
49 end;
50 end;
51 end;
52 finally
53 f.Free;
54 keyNames.Free;
55 keyVersions.Free;
56 keyInfos.Free;
57 end;
58 end;
|