【发布时间】:2020-03-31 20:22:41
【问题描述】:
我正在开发一个 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;
请帮忙,我将不胜感激:)
我已禁用优化,但它似乎仍然拒绝...
【问题讨论】:
-
我的猜测是代码被优化掉了,因为您没有使用任何计算值。通常,您在编译代码时会收到警告。但我们需要先看到一个完整的代码示例来展示这种行为,然后才能得出任何结论。
-
用minimal reproducible example 回答很容易。顺便说一句,永远不要写
if bool = false或if bool = true。而是写if not bool或if bool。 -
我现在将 yCo1、xCo1 变量更改为全局变量,它似乎对此很满意。我假设优化然后相信它在其他地方很重要。
标签: delphi debugging delphi-2010 execution