Delphi: 'GoTo' 命令未在 'with' 内编译

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

当编译这样一段代码时:

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;

我收到这条奇怪的编译器错误消息:

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

如果我删除 'with' 行,错误就会消失。

在我的真实程序中,'goto' 命令将用于退出嵌套很重的代码,其中安全退出的逻辑是曲折的。

如有任何帮助,我们将不胜感激。

编辑:我刚刚发现 Delphi 正在正确编译代码。但是消息错误仍然显示在'Structure view'.

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

好吧,这改变了一些事情,并解释了为什么我无法重现编译器错误。

IDE 用于解析代码的工具与用于编译它的工具不同。 IDE 使用的工具已知包含许多缺陷。显然你已经找到了。提交 Delphi 2006 的错误报告实际上没有任何意义。您应该学会忽略错误。