C
crazycock
Unregistered / Unconfirmed
GUEST, unregistred user!
上一个问题(http://www.delphibbs.com/delphibbs/dispq.asp?lid=3157909 )在piao40993470的帮助下解决了。现在又有新问题了。
如果得到Automation中方法的参数的类型?
方法、属性和参数都可以得到了,参数的类型呢?怎么得到?《Delphi COM深入编程》书中没有提到,搞得我查了半天资料也没有查到,偶尔有一点VC的资料,看了半天也是没有获取参数类型的代码,晕菜~
还请大家多多指点,也请piao40993470帮忙看看。
付一段《Delphi COM深入编程》中的例程。
procedure TForm1.LoadInterface(TypeInfo:ITypeInfo;TypeAttrTypeAttr);
var
TypeLibNode:TTreeNode;
AName:WideString;
ADOcString:WideString;
AHelpContext:LongInt;
FunctionsNode:TTreeNode;
FunctionNode:TTreeNode;
FuncIndex:Integer;
FuncDescFuncDesc;
ParametersNode:TTreeNode;
ParamIndex:Integer;
NamesBStrList;
cNames:Integer;
begin
TypeInfo.GetDocumentation(-1,@AName,@ADocString,@AHelpContext,nil);
if TypeAttr.typekind=TKIND_DISPATCH then
TypeLibNode:=treeT1.Items.AddChild(FDispatchRoot,AName)
else
TypeLibNode:=treeT1.Items.AddChild(FInterfaceRoot,AName);
treeT1.Items.AddChild(TypeLibNode,GUIDToString(TypeAttr.guid));
treeT1.Items.AddChild(TypeLibNode,'Version '+IntToStr(TypeAttr.wMajorVerNum)+'.'+IntToStr(TypeAttr.wMinorVerNum));
if ADOcString<>'' then
treeT1.Items.AddChild(TypeLibNode,'Help string:'+ADocString);
if AHelpContext<>0 then
treeT1.Items.AddChild(TypeLibNode,'Help context:'+IntToStr(AHelpContext));
New(Names);
try
//载入函数
FunctionsNode:=treeT1.Items.AddChild(TypeLibNode,'Functions');
for FuncIndex:=0 to TypeAttr.cFuncs-1 do begin
TypeInfo.GetFuncDesc(FuncIndex,FuncDesc);
try
TypeInfo.GetDocumentation(FuncDesc.memid,@AName,@ADocString,@AhelpContext,nil);
FunctionNode:=treeT1.Items.AddChild(FunctionsNode,AName);
if ADOcString<>'' then
treeT1.Items.AddChild(FunctionNode,'Help string:'+ADocString);
if AHelpContext<>0 then
treeT1.Items.AddChild(FunctionNode,'Help context:'+IntToStr(AHelpContext));
if FuncDesc.cParams>0 then begin
//载入参数
ParametersNode:=treeT1.Items.AddChild(FunctionNode,'Paramerters');
TypeInfo.GetNames(FuncDesc.memid,Names,SizeOf(TBStrList),cNames);
//Skip Names[0] -it's the function name
for ParamIndex:=1 to FuncDesc.cParams do
treeT1.Items.AddChild(ParametersNode,Names[ParamIndex]);
end;
finally
TypeInfo.ReleaseFuncDesc(FuncDesc);
end;
end;
finally
Dispose(Names);
end;
end;
如果得到Automation中方法的参数的类型?
方法、属性和参数都可以得到了,参数的类型呢?怎么得到?《Delphi COM深入编程》书中没有提到,搞得我查了半天资料也没有查到,偶尔有一点VC的资料,看了半天也是没有获取参数类型的代码,晕菜~
还请大家多多指点,也请piao40993470帮忙看看。
付一段《Delphi COM深入编程》中的例程。
procedure TForm1.LoadInterface(TypeInfo:ITypeInfo;TypeAttrTypeAttr);
var
TypeLibNode:TTreeNode;
AName:WideString;
ADOcString:WideString;
AHelpContext:LongInt;
FunctionsNode:TTreeNode;
FunctionNode:TTreeNode;
FuncIndex:Integer;
FuncDescFuncDesc;
ParametersNode:TTreeNode;
ParamIndex:Integer;
NamesBStrList;
cNames:Integer;
begin
TypeInfo.GetDocumentation(-1,@AName,@ADocString,@AHelpContext,nil);
if TypeAttr.typekind=TKIND_DISPATCH then
TypeLibNode:=treeT1.Items.AddChild(FDispatchRoot,AName)
else
TypeLibNode:=treeT1.Items.AddChild(FInterfaceRoot,AName);
treeT1.Items.AddChild(TypeLibNode,GUIDToString(TypeAttr.guid));
treeT1.Items.AddChild(TypeLibNode,'Version '+IntToStr(TypeAttr.wMajorVerNum)+'.'+IntToStr(TypeAttr.wMinorVerNum));
if ADOcString<>'' then
treeT1.Items.AddChild(TypeLibNode,'Help string:'+ADocString);
if AHelpContext<>0 then
treeT1.Items.AddChild(TypeLibNode,'Help context:'+IntToStr(AHelpContext));
New(Names);
try
//载入函数
FunctionsNode:=treeT1.Items.AddChild(TypeLibNode,'Functions');
for FuncIndex:=0 to TypeAttr.cFuncs-1 do begin
TypeInfo.GetFuncDesc(FuncIndex,FuncDesc);
try
TypeInfo.GetDocumentation(FuncDesc.memid,@AName,@ADocString,@AhelpContext,nil);
FunctionNode:=treeT1.Items.AddChild(FunctionsNode,AName);
if ADOcString<>'' then
treeT1.Items.AddChild(FunctionNode,'Help string:'+ADocString);
if AHelpContext<>0 then
treeT1.Items.AddChild(FunctionNode,'Help context:'+IntToStr(AHelpContext));
if FuncDesc.cParams>0 then begin
//载入参数
ParametersNode:=treeT1.Items.AddChild(FunctionNode,'Paramerters');
TypeInfo.GetNames(FuncDesc.memid,Names,SizeOf(TBStrList),cNames);
//Skip Names[0] -it's the function name
for ParamIndex:=1 to FuncDesc.cParams do
treeT1.Items.AddChild(ParametersNode,Names[ParamIndex]);
end;
finally
TypeInfo.ReleaseFuncDesc(FuncDesc);
end;
end;
finally
Dispose(Names);
end;
end;