Answer the question
In order to leave comments, you need to log in
How to expect all possible descendants of a Pascal class?
It is required to specify a parent class for the field, from which all possible subclasses that will come for this field will be inherited.
Actually a problem.
If you clearly indicate that the field has the type of the parent class, then the child classes no longer pass. In languages with good OOP, this problem is solved using interfaces, how is it possible to solve the problem in Pascal?
Answer the question
In order to leave comments, you need to log in
If you clearly indicate that the field has the type of the parent class, then the child classes no longer pass.
type TParent=class
end;
type TChild=class(TParent)
end;
type TController=class
private
fClass:TParent;
public
procedure ProcessAnyChild(aClass:TParent);
end;
procedure Test();
var child:TChild;
controller:TController;
begin
child := TChild.Create();
controller := TController.Create();
controller.ProcessAnyChild(child)
end;
procedure TController.ProcessAnyChild(aClass: TParent);
begin
fClass:=aClass
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question