2

How can I get the type info from the GUID?

procedure MyProcedure(const InterfaceId: TGuid);
var
  MyTypeInfo: PTypeInfo;
begin
  MyTypeInfo := TypeInfo(InterfaceId);  //E2133 TYPEINFO standard function expects a type identifier
  ...
end;
Interferank
  • 101
  • 6
  • Can you enumerate all interfaces using RTTI and check for the ones that match your GUID – David Heffernan Feb 20 '17 at 17:37
  • That is exactly what you have to do. Easier to do in D2010 and later using Extended RTTI, but has to be [done manually](http://stackoverflow.com/questions/3107583/) in standard RTTI. – Remy Lebeau Feb 20 '17 at 17:53

1 Answers1

3

You have to search through all the RTTI in the EXE. For Delphi 2010 and above:

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.
Dave Olson
  • 1,435
  • 1
  • 9
  • 16