hi,
this should help :-)
TSubclassList = class(TClassList)
private
FParentClass:TPersistentClass;
procedure CallbackClass(AClass: TPersistentClass);
public
procedure Execute(const aClass:TPersistentClass);
end;
procedure TSubclassList.CallbackClass(AClass: TPersistentClass);
begin
if AClass.InheritsFrom(FParentClass) and (AClass<>FParentClass) then
begin
Self.Add(AClass);
end;
end;
procedure TSubclassList.Execute(const aClass: TPersistentClass);
var
f:TClassFinder;
begin
FParentClass:=aClass;
f:=TClassFinder.Create(nil);
try
f.GetClasses(CallbackClass);
finally
FreeAndNil(f);
end;
end;
-------------------------------------
example use:
TFruit = class(TPersistent);
TOrange = class(TFruit);
TBigOrange = class(TOrange);
TApple = class(TFruit);
procedure TForm1.FormCreate(Sender: TObject);
var
l:TSubclassList;
i:Integer;
begin
l:=TSubclassList.Create;
l.Execute(TFruit);
for i:=0 to l.Count-1 do
begin
ListBox1.Items.Add(l[i].ClassName);
end;
freeandnil(l);
end;
initialization
RegisterClass(TFruit);
RegisterClass(TOrange);
RegisterClass(TBigOrange);
RegisterClass(TApple);
cya,
ben
--- john rae <[EMAIL PROTECTED]> wrote:
> Hi. I would like to be able to generate class references to the subclasses
> of a given class so that I can populate a list with sub class class specific
> information and then upon user selection, use a soft coded factory method to
> instantiate the corresponding subclass. This means new subclasses can be
> added and everything will still work...
> Function TObject.parent supports upward navigation, how do I navigate down?
>
> thanks, John.
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi