名称解析如何在复合“with”语句中起作用?

时间:2011-05-16 22:08:39

标签: delphi with-statement

在以下代码中测试了哪个Ready实例,为什么?

interface

type
  TObject1 = class
  ...
  public
    property Ready: boolean read FReady write FReady;
  end;

  TObject2 = class
  ...
  public
    property Ready: boolean read FReady write FReady;
  end;

implementation

var
  Object1: TObject1;
  Object2: TObject2;

...

procedure test;
var
  Ready: boolean;
begin
  Ready:= true;
  with Object1, Object2 do begin
    if Ready then ShowMessage('which one?');
  end; {with}
end;

1 个答案:

答案 0 :(得分:13)

最后一个。

with Object1, Object2 do

相当于

with Object1 do
  with Object2 do

所以Object2将成为第一优先。

The official documentation on this matter.