Delphi Object-oriented visibility notation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.