Delphi can provide further control over objects by yogaprotected, private, public, published, and automated indicators when declaring domains and methods. The syntax for using these keywords is as follows
Tsomeobject = Classprivate aprivatevariable:integer; Anotherprivatevariable:boolean;protected procedure aprotectedprocedure; function Protectme:byte;public constructor apubliccontructor; Destructor Apublickiller;published Property Aproperty Read aprivatevariable write aprivatevariable;end;
Under each indicator is a single declarator for more than one method and domain. Writing is to note the indentation format. The following are the meanings of these indicators:
1) Private
This part of the object can only be accessed by the code of the same unit. Use this indicator to hide the implementation details from the user and organize the user to directly modify the sensitive parts of the object
2) protected
This part of the object can only be accessed by its derived classes, which will not only allow the object to hide the implementation details from the user, but not the object's derived classes provide maximum flexibility
3) Public
This part of the domain and method can be accessed anywhere in the program, and the constructor and destructor method of the object should usually be public
4) Published
This part of the object produces the run-time type information (RTTI) and enables other parts of the program to access this section. Object Inspector a list of attributes with Rtti to produce
5) Automated
This indicator is not actually used, and the purpose of this indicator is to be compatible with Delphi 2.0 code.
The following code is an Tmyobject object that was previously introduced, which improves the integrity of the object by increasing the indicator:
Tmyobject = Classprivate somevalue:integer; Procedure Setsomevalue (Avalue:integer);p ublished property Value:integer Read somevalue write setsomevalue;end; Procedure Tmyobject.setsomevalue (Avalue:integer); begin If Somevalue<>avalue then somevalue:= avalue; End
Now, the user of the object cannot directly modify the value of the S o m e Va l u e, and the data of the object must be modified by the Va L U e property.
Delphi Object-oriented visibility notation