如何从GUID获取类型信息?
procedure MyProcedure(const InterfaceId: TGuid);
var
MyTypeInfo: PTypeInfo;
begin
MyTypeInfo := TypeInfo(InterfaceId); //E2133 TYPEINFO standard function expects a type identifier
...
end;
答案 0 :(得分:3)
您必须搜索EXE中的所有RTTI。对于Delphi 2010及以上版本:
unit RTTI.Utilities;
interface
uses System.TypInfo;
function InterfaceTypeInfoOfGUID(const AGUID : TGUID) : PTypeInfo;
implementation
uses System.RTTI;
function InterfaceTypeInfoOfGUID(const AGUID : TGUID) : PTypeInfo;
var
Context : TRttiContext;
ItemType : TRttiType;
begin
for ItemType in Context.GetTypes do
begin
if ItemType is TRTTIInterfaceType then
begin
if TRTTIInterfaceType(ItemType).GUID = AGUID then
exit(TRTTIInterfaceType(ItemType).Handle);
end
end;
Result := nil;
end;
end.