G
G
GetJump2014-05-29 04:50:38
OOP
GetJump, 2014-05-29 04:50:38

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

1 answer(s)
A
Andrew, 2014-05-29
@OLS

If you clearly indicate that the field has the type of the parent class, then the child classes no longer pass.

Why don't they pass? Please provide an example code...
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 question

Ask a Question

731 491 924 answers to any question