Delphi Object-oriented properties

Source: Internet
Author: User

Attributes can be thought of as special auxiliary domains that can modify and execute code on the data in a class. For a component, a property is the contents of a column that is listed in the Object Inspector window. The following example defines a simple object with attributes

Tmyobject = Classprivate    somevalue:integer;    Procedure Setsomevalue (Avalue:integer);p ublic property    Value:integer Read somevalue write setsomevalue;end; Procedure Tmyobject.setsomevalue (Avalue:integer); begin    If somevalue <> avalue then        somevalue: = Avalue; End

Tmyobject is an object that contains the following: a domain (the number of integers called somevalue), a method (a process called a setsomevalue), and a property called value

The function of the Setsomevalue procedure is to assign a value to the Somevalue field, and the Value property does not actually contain any data. Value is a secondary domain of the somevalue domain, and when you want the value in values, it reads the value from Somevalue, and when you try to set a value on the Values property, value calls Setsomevalue to the Somevalue setting value.

There are two advantages to this:

1) First, using a simple variable allows external code to access the object's data without needing to know the implementation details of the object

2) Second, methods such as Setsomevale can be overridden in a derived class to achieve polymorphism

Delphi Object-oriented properties

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.