Delphi parameter delivery

xiaoxiao2021-03-06  34

1. Numerical parameter variables and structures are completely copied into the stack, the call function is just a copy. Numerical parameter transmission mode is the default method of delphi, is also the default parameter transfer method of most of the languages ​​(such as C , VC, Java) ...).

Form: Function Myfunc (Object: TOBJECT): Byte; Procedure MyProc (Object: TOBJECT);

PS: The stack can be understood in this way, each function or process call is called, a piece of memory created in memory is used to save the function or the temporary structure, the function or process call is completed, and this memory will be released.

2. Variable parameters are unlike numerical parameters, this parameter transmission mode, the parameter is not a copy of the argument, but a reference, the modification of the parameters in the function or process will be reflected in the parameters itself, this way is like Quote parameters in C .

Form: Function myfunc (var Object: TOBJECT): Byte; Procedure MyProc (var Object: TOBJECT);

3. Forms of constant parameters: Function myfunc (const str: string): byte; Procedure MyProc (const number: integer); here, the value of STR and Number is not allowed to be modified inside the function or process, often in order to prevent such Modifications to use const types, but you need to pay attention to Delphi, if this const parameter is an object, the properties of this object can be modified, but in C , Java, the properties of the Const type object are not allowed Modified.

***** The situation needs to be paid attention to, see this C function void cdepart :: ShowMebername (const cpeople * ppeople) {cpeople * ptr = new cpeople (); ppeople = ptr; cout << ppeople-> m_name < m_name << endl;}

4. Array parameter Type MyArray: array [0..50] of byte; ......... Function myfunc (Temparray: myarray): byte; ........ actually Commonly used the following form, the upper bound of array is uncertain in function myfunc (Temparray: Array): byte; var i: integer; begin i: = high (tempArray); // high Returns the upper bound of Temparray;

转载请注明原文地址:https://www.9cbs.com/read-66320.html

New Post(0)