Improvements for 6 Classes
Original Reporter info from Mantis: PascalDragon @PascalDragon
-
Reporter name: Sven Barth
Original Reporter info from Mantis: PascalDragon @PascalDragon
- Reporter name: Sven Barth
Description:
The following points are potential improvements for the section 6 Classes:
Destructors and class destruction in general should be mentioned: Always called "Destroy", needs to have "override" and no parameters. When called the class instance is freed at the end. Should call the inherited destructor somewhere. "Destroy" does not check whether instance is Nil while "Free" does.
Static class methods: have a "static" modifier at the end; don't have a "Self" parameter; can't be virtual; behave like normal, global procedures/functions and can be assigned to normal procedure variables (note: AFAIK this does not work in 2.6.x because of a bug that was fixed some months ago in 2.7.1...)
Class procedures can be used as getters and setters for class properties.
Class properties should also be explained (together with class fields that are shared by all instances of this class and all subclasses).
Also there are class constructors and destructors: Take no arguments, can not be virtual, are always name "Create" respectively "Destroy". Class constructors are executed before a unit's initialization section and class destructors after the execution of the finalization section. (And at least in theory constants and global variables in a unit are initialized before class constructors and destructed after class destructors, but that is currently not the case...)
Maybe one should also explicitely mention that array properties can have multiple indices.
Also default properties can be redeclared by subclasses (good example: TFPObjectList which redeclares Items as being of type TObject instead of Pointer)
Mantis conversion info:
- Mantis ID: 25661
- Version: 2.6.2
- Fixed in version: 3.0.0
- Fixed in revision: 1080 (#bb18662a)
- Target version: 2.6.4