Delphi 好像忽略了我的一些代码行?

Delphi seems to ignore some of my lines of code?

我有一个正在开发的 VCL Delphi 应用程序,但是 Delphi 似乎拒绝执行我的某些代码行,DrawLine 是一个私有函数...

if not(FirstCoords) then
        begin
          firstcoords := true;
          xCo1 := xCoPre + LeftOffset;
          yCo1 := yCoPre + TopOffset;
        end
      else
        begin
          xCo2 := xCoPre + LeftOffset;
          yCo2 := yCoPre + TopOffset;
          DrawLine(xCo1, xCo2, yCo1, yCo2);
          bbtFieldScale.Click;
        end;

当我单步调试时,它执行 If,然后继续将 "firstcoords" 设置为 true,但随后跳转到 If 的末尾,甚至没有触及其他两行...如果我添加一行如下代码,然后似乎执行代码...

if not(FirstCoords) then
        begin
          firstcoords := true;
          xCo1 := xCoPre + LeftOffset;
          yCo1 := yCoPre + TopOffset;
          showmessage(inttostr(xCo1+yCo1));
        end
      else
        begin
          xCo2 := xCoPre + LeftOffset;
          yCo2 := yCoPre + TopOffset;
          DrawLine(xCo1, xCo2, yCo1, yCo2);
          bbtFieldScale.Click;
        end;

请帮忙,我将不胜感激:)

我已经禁用了优化,但它似乎仍然拒绝...

当有问题的操作被优化掉时,你描述的情况就会发生,因为分配给的变量没有在代码的其他任何地方使用,并且编译器看不到明显的一面消除这些操作的影响。

一旦您添加了 ShowMessage(),相关变量就会变得相关,因此无法再消除它们的赋值。