What is the purpose of the "list of ancestors" in class helper syntax? Where is it documented? Is there any use case?

All documentation versions, including the most recent version , give the following class / record helper syntax:

type identifierName = class|record helper [(ancestor list)] for TypeIdentifierName memberList end; 

And this only explains that ...

The list of ancestors is optional. It can only be specified for a helper class.

... and further not go into details. Examples of use in the rest of the documentation document simply take advantage of the fact that the ancestor list is optional. All the EMBA code I saw, as well as all the third-party code, does not use this part of the ancestor list .

So my questions are stated in the title:

  • What is the purpose of ancestor list in class helper syntax?
  • Where is it documented?
  • Is there any use case?
+5
source share
1 answer

It allows you to inherit assistants:

 {$APPTYPE CONSOLE} type TObjectHelper = class helper for TObject procedure Foo; end; TObjectHelperAgain = class helper(TObjectHelper) for TObject procedure Bar; end; procedure TObjectHelper.Foo; begin Writeln('Foo'); end; procedure TObjectHelperAgain.Bar; begin Writeln('Bar'); end; begin with TObject.Create do begin Foo; Bar; end; end. 

This is one way around a limitation that only one helper can contain anywhere in the code.

As far as I can tell, there is no documentation for the list of ancestors.

+4
source

Source: https://habr.com/ru/post/1203041/


All Articles