(1 ) var modifier
Adding Var is an address pass that modifies the original variable
Var
s:string;
Begin
S: = ' Hello ';
Changesvar (s);
ShowMessage (S);
End
Changesvar definition
Procedure Tform1.changesvar (var a:string);
Begin
A: = A + ' world ';
End
The above will output Hello world, because it is the address, modify the original A
(2 ) without any modifiers
Var
s:string;
Begin
S: = ' Hello ';
Changes (s);
ShowMessage (S);
End
Changes definition
Procedure Tform1.changes (a:string);
Begin
A: = A + ' world ';
End
The above will output hello, because the method changes actually creates a new a, and the output is the original A, the value does not change
(3 ) out modifier
Var
s:string;
Begin
S: = ' Hello ';
Changesout (s);//At this time the value of S is ' Hello ' instead of ' Hello,world '!, the original value of s in the procedure Hello is discarded
ShowMessage (S);
End
Changesout definition
Procedure Tform1.changesout (out a:string);
Begin
A: = A + ' world ';
End
The above output world,out only accept the returned value, and any input to out will be ignored. The actual arguments that are passed to the procedure at the same time do not have to be initialized, such as calls to Changesout:
Var
tmp:string;
Begin
Changesout (TMP);//compilation can also be done by
End;
(4) Const modifier
Const-decorated parameters are not allowed to be modified after they are passed in
If you modify parameters in the process, you will get an error, such as:
Procedure xxxx. Testconst (const a:string);
Begin
A: = ' ss '; Attempt to modify const modified parameters will be an error
End;
var, out, and const in Delphi function parameter decoration