1

I use Delphi 10.3. It is a kind of routine to get the corresponding TRTTIType for instance variables. But is there any way to fill the gap marked as * missing code * here:

function getGenericTypeName<T> : string;
var
  ctx : TRTTIContext;
  aRT : TRTTIType;
begin
  ctx := TRTTIContext.Create;
  try
    aRT := *** missing code for T *** // Get the TRTTIType for type T
    result := aRT.Name;
  finally
    ctx.Free;
  end;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444
SOLID Developper
  • 672
  • 4
  • 12

1 Answers1

4

You are looking for

ctx.GetType(TypeInfo(T))
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thx! I tried TypeInfo without the ctx.GetType but it said 'Record, Class or Interface type requiered'... Now I retype the code and it compiles fine! :) – SOLID Developper May 19 '20 at 11:14