63456

Question:
I want use reflection on the current class inside a class procedure/function (static method). How can I do without using the "Self" keyword? And without harcode the class name: this procedure should be override in the descendants.
class procedure AAA.SetTableAndSequence;
var
c : TRttiContext;
t : TRttiType;
begin
c := TRttiContext.Create;
try
t := c.GetType(Self.ClassType);
...
finally
c.Free;
end;
end;
Answer1:You can use <a href="http://docwiki.embarcadero.com/Libraries/XE6/en/System.TObject.ClassInfo" rel="nofollow">ClassInfo
</a> and <a href="http://docwiki.embarcadero.com/Libraries/XE6/en/System.Rtti.TRttiContext.GetType" rel="nofollow">GetType
</a>:
class procedure AAA.SetTableAndSequence;
var
c: TRttiContext;
t: TRttiType;
begin
t := c.GetType(ClassInfo);
...
end;