Author: Nik Ozniev
Recently I developed Automation Server for reports in Word and was surprised with
failure trying to get Help String for TypeLibrary
Answer:
Recently I developed Automation Server for reports in Word and was surprised with
failure trying to get Help String for TypeLibrary by following code
1 var
2 k, InfoCount: Integer;
3 TypeLib: ITypeLib;
4 TypeLibGUID: TGUID;
5 ErrorStr: string;
6 HRes: HResult;
7 pbstrDocString, pbstrName: WideString;
8 begin
9 Memo1.Lines.Clear;
10 // InputGUIDString is given input string value
11 TypeLibGUID := StringToGUID(InputGUIDString);
12 // loads Type Library from registry
13 HRes := LoadRegTypeLib(TypeLibGUID, 1, 0, 0, TypeLib);
14 if Failed(HRes) then
15 Exit;
16
17 // believing in mind, that so it is in practice!
18 InfoCount := TypeLib.GetTypeInfoCount;
19 for k := 0 to kInfoCount - 1 do
20 begin
21 HRes := TypeLib.GetDocumentation(k, @pbstrName, @pbstrDocString, nil, nil);
22 if Failed(HRes) then
23 Continue;
24 Memo1.Lines.Add(pbstrName + ': ' + pbstrDocString);
25 end;
Here was no errors!
But the thing is that help string for Type Library resides beyond the range
[0..kInfoCount-1] so TypeLib.GetTypeInfoCount reports about ITypeInfo count,
excluding ITypeInfo for himself. Did you know about it?
To get Help String for self Type Library one must implement
TypeLib.GetDocumentation(-1, @pbstrName, @pbstrDocString, nil, nil);
Isn't it unexpectedly for Delphi programmers? I didn't found anything about it in Delphi help!
|