是否可以通过参数按值和稍后在运行时调用相同的函数定义?就像是:
function myfunc(a:string);
begin
a:='abc';
end;
...
later:
b:='cde';
myfunc(b);
caption:=b; //prints 'cde'
...
later:
myfunc(@b);
caption:=b; //prints 'abc'
Run Code Online (Sandbox Code Playgroud)
??
功能不一样,没有.您需要使用重载函数,例如:
function myfunc(a: string); overload;
begin
// use a as needed, caller is not updated...
a := 'abc';
end;
function myfunc(a: PString); overload;
begin
// modify a^ as needed, caller is updated...
a^ := 'abc';
end;
Run Code Online (Sandbox Code Playgroud)
b := 'cde';
myfunc(b);
Caption := b; //prints 'cde'
Run Code Online (Sandbox Code Playgroud)
b := 'cde';
myfunc(@b);
Caption := b; //prints 'abc'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
162 次 |
| 最近记录: |