procedure TForm1.Button1Click(Sender: TObject);
Var
  a:Byte;
  b:Word;
  c:LongWord;
  d:Integer;
  e:Int64;
begin
  a:=1;
  b:=a+4;
  inc(a);
  inc(b);
  inc(c);
  inc(d);
  inc(e);
end;透过cpu view看汇编代码,发现根本就不执行那几个语句。
只有Begin 和End 的代码:
add esp,-$08
pop ecx
pop edx
ret

解决方案 »

  1.   

    一路跟踪过去,发现如下call语句:(只写调用函数或过程的call语句)
    add esp,-$08
    pop ecx
    pop edx
    retcall dword ptr [ebx+$00000120]call TControl.clickCall @CallDynaInstcall dword ptr [ecx-$14]Call TControl.WndProcCall TWinControl.WndProcCall dword ptr [ebx+$38]Call TControl.PerformCall DoControlMsgtest al,aljnz +$09
    mov edx,ebx
    mov eax,esi
    mov ecx,[eax]
    call dword ptr [ecx-$10]
    pop esi
    pop ebx
    retCall TWinControl.WMCommandCall dword ptr [ecx-$14]call TControl.WndProcCall TWinControl.WndProcCall Dword ptr [ebx+$38]
      

  2.   

    TControl.WndProc 和TwinControl.WndProc既然执行了两次。或者跟多。跟踪到最后就不想继续了。
      

  3.   

    :-) yes被优化了 这就是DELPHI 编译器的强悍处。
      

  4.   

    你没看到编译的时候有很多信息?[Hint] Unit1.pas(39): Value assigned to 'e' never used
    [Hint] Unit1.pas(38): Value assigned to 'd' never used
    [Hint] Unit1.pas(37): Value assigned to 'c' never used
    [Hint] Unit1.pas(36): Value assigned to 'b' never used
    [Hint] Unit1.pas(35): Value assigned to 'a' never used
    [Hint] Unit1.pas(34): Value assigned to 'b' never used
    [Hint] Unit1.pas(33): Value assigned to 'a' never used
      

  5.   

    呵呵!是啊,是啊!delphi优化功能是很强悍!
    jnz +$09这个是不是说从当前指令地址+9字节的跳转?
      

  6.   

    大家都说完了,呵呵。Delphi说,你写了又不用,还不如不写,还是关掉吧。
      

  7.   

    Delphi说,你白痴,我不白痴,就不给你编译!气死你,有本事去csdn发帖!
      

  8.   

    是使用了,但是在你写
    inc(a);
    inc(b);
    inc(c);
    inc(d);
    inc(e);
    之后,再也没有引用上面的变量,Delphi编译的时候就已经进行优化处理了,你可以试试
    随便加一句在inc(e)的后面写,showmessage(inttostr(a));那inc(a)会执行,接下来的不会执行,直到showmessag这一句才会继续执行