Is there at way, at runtime, to find all classes that descend from a particular base class?
For example, pretend there is a class:
TLocalization = class(TObject)
...
public
function GetLanguageName: string;
end;
or pretend there is a class:
TTestCase = class(TObject)
...
public
procedure Run; virtual;
end;
or pretend there is a class:
TPlugIn = class(TObject)
...
public
procedure Execute; virtual;
end;
or pretend there is a class:
TTheClassImInterestedIn = class(TObject)
...
public
procedure Something;
end;
At runtime i want to find all classes that descend from TTestCase
so that i may do stuff with them.
Can the RTTI be queried for such information?
Alternatively: Is there a way in Delphi to walk every class? i can then simply call:
RunClass: TClass;
if (RunClass is TTestCase) then
begin
TTestCase(RunClass).Something;
end;
See also
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…