Process and function parameters

Source: Internet
Author: User
Parameters are included in the Declaration headers of most processes and functions, such:
Function sum (X: integer; Y: integer): integer;
The parameter list is (X: integer; Y: integer), which can be divided into form parameters and real parameters. Parameters are in the parameter list during the process and function declaration, while real parameters are in the parameter list during function call. Note that when there are more than one parameter in the process and function declaration, the parameter should be separated by a semicolon. Multiple parameters are separated by commas.
During the call, parameters in the parameter list must be consistent with those in the actual parameter list in quantity and order. Otherwise, a compilation error or a result error may occur. However, if the parameter data type in the parameter list does not match the parameter data type in the parameter list, the compiler automatically converts the type. When declaring a process or function, you can assign an initial value to it by adding "=" to the parameter definition and then a constant.
The Object Pascal transmits parameters to functions and procedures through values or references. The passed parameters can be basic types, user-defined types, or open arrays.
1. Passing value Parameters
The value parameter is passed as a value, and the value parameter is used in the preceding routine. For example:
Procedure sum (X: integer; Y: integer );
Call time:
Sum (A, B );
Here, the values of real parameters A and B are passed to the X and Y parameters respectively.
2. Process and function reference parameters
When the Object Pascal can pass a variable to a process or function by referencing a parameter, the process and function of receiving the variable can change the value of the variable. In this case, the reserved word VaR is used. The function of VaR is to assign the address of the variable, and the value of the variable is changed. The following is an example of a reference parameter.
Function referencepara (var x: integer): integer;
Begin
X: = 21;
End;
X has its value changed during the call.
3. Constant parameters of processes and functions
In actual programming, sometimes we do not want to change the parameter values of the transfer process and function. In this case, we can use the reserved word const to declare it. The reserved word const can ensure that the value of the variable is not modified, which plays a good role in some cases. The declaration method is as follows:
Procedure mydata (const name: string );

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.