4

我有一个 TGUID 变量,我想通过 Rtti 将它“转换”为描述该接口的 PTypeInfo ..

AGUID := StringToGUID('{19BB9F78-1FB1-4B0F-B691-82EE5CD7A941}');

.. transform AGUID to PTypeInfo ..

AInterface = GlobalContainer.Resolve( <PTypeInfo> expected);

德尔福 2010+

4

1 回答 1

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;
于 2012-04-25T08:50:28.873 回答