我有一个TGUID变量,我希望通过Rtti将其“转换”为描述该接口的PTypeInfo ..
AGUID := StringToGUID('{19BB9F78-1FB1-4B0F-B691-82EE5CD7A941}');
.. transform AGUID to PTypeInfo ..
AInterface = GlobalContainer.Resolve( <PTypeInfo> expected);
Delphi 2010 +
答案 0 :(得分:6)
function GetInterfaceTypeInfo(const GUID: TGUID): PTypeInfo;
var
Ctx: TRttiContext;
AType: TRttiType;
begin
Result := nil;
Ctx := TRttiContext.Create;
try
for AType in Ctx.GetTypes do
if (AType.TypeKind = tkInterface) and IsEqualGUID(GetTypeData(AType.Handle)^.Guid, GUID) then
begin
Result := AType.Handle;
Break;
end;
finally
Ctx.Free;
end;
end;