Search code examples
delphidelphi-2006

Delphi: 'GoTo' command does not compile inside 'with'


When compiling a piece of code like this:

01  function MyGotoDecision: boolean;
02  begin
03    {code ...}
04  end;
05 
06  procedure TForm1.Button1Click(Sender: TObject);
07  label MyLabel;
08  begin
09    with Application do
10    begin
11      {code ...}
12      if MyGotoDecision then
13        goto MyLabel;
14      {more code ...}
15    end;
16    MyLabel:
17      {more code ...}
18  end;

I get this strange compiler error message:

'Void' does not contain a member named 'MyLabel' at line 13

If I remove the 'with' line, the error disappears.

In my real program the 'goto' command will be used to exit from a heavily nested code, where the logic to safely exit is tortuous.

Any help would be appreciated.

Edit: I have just found that Delphi is compiling correctly the code. But the message error still is shown in 'Structure view'.


Solution

  • I have just found that Delphi is compiling correctly the code. But the message error still is shown in 'Structure view'.

    Well, that changes things a little then, and explains why I could not reproduce a compiler error.

    The tools used by the IDE to parse code are not the same as the tools used to compile it. The tools used by the IDE are known to contain many defects. Clearly you have found one. There's not really any point in submitting a bug report for Delphi 2006. You should simply learn to ignore the error.