There is a class TParent with the preparation of the function draw , which performs some actions. There is a class TClass = class(TParent) , which complements the draw function as follows:

 function TClass.draw(): boolean; begin inherited; //Тут остальные действия end; 

There is a TList object inside the main program object, which contains a list of objects of any classes created on the basis of TParent , including TClass . This object is written inside the TParent class:

 TParent = class objects: TList; ... end; 

Inside the draw function of the TParent class, the following code is executed:

 begin for i := 0 to objects.count - 1 do TParent(objects[i]).draw(); end; 

The problem is that if there is an object of class TClass (or any one created on the basis of TParent ) inside objects , then its implementation of the draw method is not called — only the method written inside the TParent . How is this solved?

  • @Kromster, thanks, that was the problem. - nup

1 answer 1

As it turned out, your TParent and TClass did not have virtual permissions to override ( virtual ) and perform override ( override ).

 TParent = class function Draw: boolean; virtual; TClass = class(TParent) function Draw: boolean; override;