Technical Exchange, DH explanation.
Haha, I haven't written this series for a long time. Today I'm watching VCLSource codeYou saw this.
I 'd like to declare that this is only available in Versions later than D7. Thank you, don't spray me!
When we want to add a method or member variable to a class, but this class is referenced by many units, it is unwise to directly access this class. What should we do?
By the way, if it is object-oriented, We can inherit it. It is OK. But what if it is a struct? In fact, this key is more like preparing for the struct.
But here I want to talk about the usage of a helper keyword.
Class assistant can extend a class without inheritance and does not exist in UML.
Simple Syntax:
TypeHelper class name= Class helper [(Base class list)]Extended Class NameMember Variable listEnd; we can see that it is very simple, that is, class helper. of course, here I have to talk about it. record is also acceptable. who is the nickname of a record. we can define multiple helper classes for a class, but extend the attributes of the original class.CodeThe helper class can only have 0 or 1.
Here is a simple example.
Type
Tmyclass =
Class
Procedure Myproc;
Function Myfunc: integer;
End ;
...
Procedure Tmyclass. myproc;
VaR
X: integer;
Begin
X: = myfunc;
End ;
Function Tmyclass. myfunc: integer;
Begin
...
End ;
Next is its helper class.
Type
Tmyclasshelper =
Class Helper
For Tmyclass
Procedure Helloworld;
Function Myfunc: integer;
End ;
...
Procedure Tmyclasshelper. helloworld; // new method to be added
Begin
Writeln (self. classname );
End ;
Function Tmyclasshelper. myfunc: integer; // overwrite the original method
Begin
...
End ;
Usage:
VaR
X: tmyclass;
Begin
X: = tmyclass. Create;
X. myproc;
// Call tmyclass. myproc
X. helloworld;
// Call tmyclasshelper. helloworld
X. myfunc;
// Call tmyclasshelper. myfunc
End .
It's that simple. I hope you can use it.
I am DH today;