Reputation: 3756
I have a TGUID variable, and I want to "transform" it via Rtti to the PTypeInfo that describes that interface..
AGUID := StringToGUID('{19BB9F78-1FB1-4B0F-B691-82EE5CD7A941}');
.. transform AGUID to PTypeInfo ..
AInterface = GlobalContainer.Resolve( <PTypeInfo> expected);
Delphi 2010+
Upvotes: 4
Views: 596
Reputation: 37221
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;
Upvotes: 6