无,这种骗子不是read。 <代码>Const 防止添加-ref,这样,另一条面的改动就会以不可预测的方式影响其价值。 抽样方案,在<代码>定义中尝试修改<代码>const P :
{$apptype console}
uses SysUtils, Classes, SyncObjs;
type
TObj = class
public
S: string;
end;
TWorker = class(TThread)
public
procedure Execute; override;
end;
var
lock: TCriticalSection;
obj: TObj;
procedure P(const x: string);
// procedure P(x: string);
begin
Writeln( P(1): x = , x);
Writeln( Releasing obj );
lock.Release;
Sleep(10); // give worker a chance to run
Writeln( P(2): x = , x);
end;
procedure TWorker.Execute;
begin
// wait until TMonitor is freed up
Writeln( Worker started... );
lock.Acquire;
Writeln( worker fiddling with obj.S );
obj.S := bar ;
TMonitor.Exit(obj);
end;
procedure Go;
begin
lock := TCriticalSection.Create;
obj := TObj.Create;
obj.S := foo ;
UniqueString(obj.S);
lock.Acquire;
TWorker.Create(False);
Sleep(10); // give worker a chance to run and block
P(obj.S);
end;
begin
Go;
end.
但是,它不仅局限于深层;修改基本变形地点具有类似影响:
{$apptype console}
uses SysUtils, Classes, SyncObjs;
type
TObj = class
public
S: string;
end;
var
obj: TObj;
procedure P(const x: string);
begin
Writeln( P(1): x = , x);
obj.S := bar ;
Writeln( P(2): x = , x);
end;
procedure Go;
begin
obj := TObj.Create;
obj.S := foo ;
UniqueString(obj.S);
P(obj.S);
end;
begin
Go;
end.