Definitions of three variables in Delphi + variables and constants

Source: Internet
Author: User
Tags define local

The three general interpretations are as follows:

Global variables: variables declared outside the class. Generally, these variables are valid throughout the project, that is, they can be used throughout the project. The life cycle of the variable is valid when the project is created and destroyed when the project is destroyed.

Class variable: it refers to the variables declared in the class, which can be used in methods in the class. Its lifecycle is valid when the class is created and destroyed when the class is destroyed.

Local variable: refers to the variable declared inside the method. This variable can only be used inside the method. Its life cycle is also valid within the method. After the method call is completed, the declared variables in the method are also destroyed.

Global variables are placed under public. Similar to the public a as string global variable in the class module of VB

Under the class variable private, I personally understand why VB is similar. Is a global variable in the class module. The form is unavailable.

Local variables are easy to understand. Local variables in the local variable event in the form

I don't know if it means this. If it is not for future study

'================================================ I am a split line ====

Global variables:

If we define a global variable between the interface keyword and implementation keyword in a unit of the application, if the unit is referenced elsewhere, then the unit is full
Local variables can be accessed elsewhere. Of course, we can also define global variables after the implementation keyword in a unit of the application. However, the global variables defined here can only be in the local
It is private to the unit and cannot be accessed by other units. Global variables are allocated memory in the Data zone of the application. They exist in
Within the file image, it is determined during the program compilation period until the application ends. The memory address occupied by the global variable remains unchanged. Global non-pointer type. The memory is automatically allocated and the value is initialized.

Global pointer type. The memory is not automatically allocated after the Declaration. The value is nil.


Local variables:

We can define local variables in functions or methods (including processes). Local variables are allocated on the Application Stack and always allocated on the stack! The memory of local variables is in the function or method (inclusion process)
Allocated when called. The memory is released when the function or method (including process) Call ends. Because the top of the stack may change every time a function or method (including a process) is called, the memory location of local variables
The address is changed. The local non-pointer type is declared and the memory is automatically allocated without initialization value. The value is uncertain (depending on the operation of other programs on the memory ). Partial pointer type. memory is not automatically allocated after declaration,

But it will randomly point to an address, so the address is not nil

 

Variable Declaration

VaR

Variable

AA: string; // 1

A, B, C: string; // 2

AA: String, BB: string; A, B, C: string; // 3

Const

Constant

AA = 111; // 1

BB = 222; // 2

AA: String = 'xxx'; // 2

Definitions of three variables in Delphi + variables and constants

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.