Is it possible to get the value of a GUID on an interface using RTTI?
Asked Answered
S

2

15

If I have an interface such as:

IPluginAPI = interface
['{590DFF0B-CA00-46CC-84B0-3848103D4C5A}']
   function add (a : double; b : double) : double;
   function sub (a : double; b : double) : double;
   function mult (a : double; b : double) : double;
   function divide (a : double; b : double) : double;
end;

Is there anyway to get the value of the GUID using RTTI? I am using Delphi XE.

Storehouse answered 8/12, 2011 at 23:36 Comment(0)
A
28
uses
  TypInfo;

Guid := GetTypeData(TypeInfo(IPluginAPI))^.Guid;
Amelita answered 8/12, 2011 at 23:43 Comment(3)
+1 Too bad the documentation is so far out of date.......Ogata
Wow, that page is outright misleading. Note to self: Always see the source.Amelita
+1, another option using the new Rtti TRttiInterfaceType(TRttiContext.Create.GetType(TypeInfo(IPluginAPI))).GUIDGershwin
G
0

As mentioned by RRUZ in comment to older reply:

uses
  System.Rtti;

//...
var Guid := TRttiInterfaceType(TRttiContext.Create.GetType(TypeInfo(IPluginAPI))).GUID;
Gosser answered 18/10, 2021 at 14:38 Comment(1)
docwiki.embarcadero.com/Libraries/Sydney/en/…Gosser

© 2022 - 2024 — McMap. All rights reserved.