Delphi declares its own class and its calling method

Source: Internet
Author: User

{Type is placed below the uses reference unit under interface }
1 //declaring classes2 type3Tmyclass =class //Note that this cannot be added '; ' because it's a whole.4Data:integer;//domain of the class5 procedureChangedata (Value:integer);//class Method (procedure) press CTRL + SHIFT + C key to automatically generate function body6 functionGetdata:integer;//method of the Class (function)7 //The fields and methods of the class can be added according to your needs8 End;9 Ten {Tmyclass} One procedureTmyclass.changedata (Value:integer); A begin -Data: = Value;// - End; the - functionTMyclass.GetData:integer; - begin -Result: =Data; + End; - + //Access Class A procedureTform1.speedbutton2click (sender:tobject); at var - Myclass:tmyclass; - I:integer; - begin - Try -MyClass: = Tmyclass.Create;//must be instantiated before use, otherwise it will not be used inMyClass. Changedata ( A);//assigns a value to the method of the class, -I: = MyClass. GetData;//gets the class toShowMessage (IntToStr (i));//{A} + finally -MyClass. Free;//Finally, you need to release the used memory the End; * End;

In addition, there are two special methods in the class, the method (Constructor) and the Destructor method (destructor) are constructed respectively.
A class is an object-oriented idea.

Delphi declares its own class and its calling method

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.