When your program code calls a process or function, it usually uses parameters to pass data to the called process or function. The most common parameters are numerical parameters, variable parameters, and constant parameters.
The parameters defined by the called process or function are form parameters, while the parameters specified by the call process or function are real parameters. In the NoValue function, it indicates that AnEditBox in the function body is a form parameter, while if NoValue (Edit1 )... In, Edit1 is a real parameter.
Only the value of the parameter is changed during the running process, and the value of the parameter is not changed. That is, the value of the parameter cannot be passed outside the process. Example:
Procedure Calculate (CalNo: Integer );
Begin
CalNo: = CalNo * 10;
End;
Use the following routine to call the Calculate function:
...
Number: = StrToInt (Edit1.Text );
Calculate (Number );
Edit2.Text: = IntToStr (Number );
...
Number accepts the value entered in the edit box 1, which is calculated by the Calculate process. It is a numeric real parameter. After entering the Calculate function, the real Number parameter will be copied to the form parameter CalNo. In the process, CalNo is increased by ten times, but it is not passed out, so the Number value has not changed, in edit box 2, it is still the input value in edit box 1. Parameters and real parameters occupy different memory addresses. When a process or function is called, the values of real parameters are copied to the memory occupied by the parameters. Therefore, after a process or function is generated, the values of the form parameter and the real parameter are different, but the values of the real parameter do not change.
If you want to change the input parameter value, you need to use the variable parameter, that is, add the reserved word var before the form parameter in the parameter table of the called program. For example:
Procedure Calculate (var CalNo: Integer );
Then CalNo does not occupy a position in the memory, but points to the real parameter Number. When a variable parameter is passed, any changes made to the parameter will be reflected in the real parameter. This is because two parameters point to the same address. Add var before the parameter CalNo in the process header in the previous example and call it with the same program. The calculation result is displayed in the second edit box, enlarge the value in the first edit box by ten times. In this case, the parameters CalNo and Number are 10 times the initial value of Nnmber.
If the process or function execution requires that the value of the form parameter be not changed, the safest way is to use constant parameters. Adding the reserved word const before the parameter table name can make a form parameter a constant parameter. Using constant parameters instead of numeric parameters can protect your parameters, so that you do not accidentally assign new values to this parameter if you do not want to change the value.