Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does name resolution work in compound "with" statements?

Which instance of Ready gets tested in the following code, and why?

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;
like image 380
Johan Avatar asked Dec 13 '22 13:12

Johan


1 Answers

The last one.

with Object1, Object2 do

is equivalent to

with Object1 do
  with Object2 do

and so Object2 will be the number-one priority.

The official documentation on this matter.

like image 99
Andreas Rejbrand Avatar answered Jan 21 '23 15:01

Andreas Rejbrand