请帮助,Delphi似乎忽略了我的某些代码行?

问题描述 投票:-1回答:1

我有一个正在使用的VCL Delphi应用程序,但是Delphi似乎拒绝执行我的某些代码行...

if FirstCoords = false then
        begin
          firstcoords := true;
          xCo1 := xCoPre + LeftOffset;
          yCo1 := yCoPre + TopOffset;
          I := xCo1 + yCo1;
        end;

当我逐步调试时,它将执行If,然后继续将“ firstcoords”设置为true,但是然后直接跳至If的末尾,甚至不碰其他三行...如果我添加诸如下面的代码,那么它似乎执行了代码...

if FirstCoords = false then
        begin
          firstcoords := true;
          xCo1 := xCoPre + LeftOffset;
          yCo1 := yCoPre + TopOffset;
          I := xCo1 + yCo1;
          ShowMessage(IntToStr(I));
        end

[请帮助,我会很感激:)

delphi debugging delphi-2010 execution
1个回答
0
投票

当所讨论的操作被优化]时,您所描述的会发生,因为分配给变量的变量未在代码中的其他任何地方使用,并且编译器看不到消除这些操作的明显副作用。

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

© www.soinside.com 2019 - 2024. All rights reserved.