相关疑难解决方法(0)

Delphi通过引用或值/副本传递参数

背景1

var text:String;

text:='hello';

myFunc(text);
Run Code Online (Sandbox Code Playgroud)

上下文2

function myFunc(mytext:String);
var textcopy:String;
begin

    textcopy:=mytext;

end;
Run Code Online (Sandbox Code Playgroud)

myFunc从Context1调用Context2,局部变量mytext指向Context2之外的内存?或者在mytext范围内有自己的内存空间,并用相同的内容填充/复制text?我可能遗漏了一些非常基本的东西,因为我收到了一个access violation错误.

有没有办法明确指定一个函数是应该通过引用还是通过值接收参数,然后像C一样复制?我不确定我是怎么做的.

delphi pascal pointers pass-by-reference

10
推荐指数
3
解决办法
3万
查看次数

标签 统计

delphi ×1

pascal ×1

pass-by-reference ×1

pointers ×1