I have a VCL Delphi application I am working on, but Delphi seems to refuse to execute some of my lines of code, DrawLine is a private function...
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;
when I step through debugging, it executes the If, then proceeds to set "firstcoords" to true, but then just jumps to the end of If, without even touching the other two lines... If I add a line such as the code below, then it seems to execute the code...
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;
Please help, I would really appreciate it :)
I have disabled optimization, but it still seems to refuse...
What you describe happens when the operations in question are optimized away because the variables being assigned to are not being used anywhere else in your code, and the compiler sees no noticeable side effects in eliminating those operations.
As soon as you added the ShowMessage()
, the variables in question became relevant, so their assignments could not be eliminated anymore.