Re:Return a list of Derived Classes
Quote
"Damjan" <damjan.veng...@kompozitemra.si> wrote in message news:j3Ef9.1584
> I would like to load 'ClassName' of all classes derived form TDevice into
> ComboBox. And than at RunTime select a 'ClassName' from ComboBox, Create
the
> object of selected type and Add it to the collection (TDevices).
The list of registerd classes is declared and maintained in the
Implementation section of one of the VCL units (I can't remember which one
off-hand). Without implementing your own mechanism for tracking descendants
its going to be quite difficult. I'd suggest that you implement a
RegisterDescendant<classname> procedure that maintains a list of descendant
classes:
type
tSomeClassClass = class of tSomeClass;
procedure RegisterSomeClassDescendant (aClass : tSomeClassClass);
procedure GetSomeClassDescendantNames (results : tStrings);
Implementation
var SomeClassDescendants : tList = tSomeClassClass;
procedure RegisterSomeClassDescendant (aClass : tSomeClassClass);
begin
if not Assigned (SomeClassDescendants)
then SomeClassDescendants := tList.Create;
if SomeClassDescendants.IndexOf (aClass) < 0
then SomeClassDescendants.Add (aClass);
end;
procedure GetSomeClassDescendantNames (results : tStrings);
var i : integer;
begin
results.BeginUpdate;
try
results.Clear;
if Assigned (SomeClassDescendants)
then begin
for i := 0 to (SomeClassDescendants.Count - 1) do
results.Add (tObject (SomeClassDescendants [i]).ClassName;
end;
finally
results.EndUpdate;
end;
end;
Finalization
if Assigned (SomeClassDescendants)
then SomeClassDescendants.Free;