procedure TForm1.BitBtn1Click(Sender: TObject);
beginp1.Caption:='1';
sleep(1000);
p1.Caption:='1111'
end;
如程序,P1是个TPANEL,bitbtn1是个按钮,我点下按钮,P1显示1,然后1秒钟后显示1111。当我再点BITBTN1时候,p1应该先显示1,1秒种后显示1111,但实际情况是,第一次显示1,1秒钟后显示1111,再点按钮得话,永远都显示1111,而不显示1,是怎么回事,有没有好得解决办法能实现我要求得功能。

解决方案 »

  1.   

    p1.Caption:='1'; 
    application.ProcessMessages;
    sleep(1000); 
    p1.Caption:='1111' 
      

  2.   

    application.ProcessMessages; 
    什么意思~
      

  3.   

    delphi帮助Interrupts the execution of an application so that it can process the message queue.Call ProcessMessages to permit the application to process messages that are currently in the message queue. ProcessMessages cycles the Windows message loop until it is empty, and then returns control to the application.
      

  4.   

    procedure TForm1.BitBtn1Click(Sender: TObject); 
    begin 
    p1.Caption:='1';
     if p1.Caption ='1' then begin
       sleep(1000); 
       p1.Caption:='1111'
     end;
     
    end; 
      

  5.   

    楼主你在撒谎吧。
    首先,你的p1的Caption不可能显示1,除非你给他设置的默认值就是1。
    显示1111是正常的。原因是:当你给p1的Caption赋值为1后,还没等刷新,就马上执行了Sleep,所以你看不见1
           当Sleep完了之后,他刚准备来显示1,你又给他赋值为1111.
    所以,你的p1的Caption显示的规律是:首先显示默认的Caption值,
          然后一直显示1111.解决办法很简单,手动的刷新,代码如下:p1.Caption:='1';
    p1.Repaint;// look here
    sleep(1000);
    p1.Caption:='1111'或者用application.ProcessMessages,也是可以的,
    执行到这里的时候CPU会“喘口气”,也就有时间刷新你的Caption了。
      

  6.   

    application.ProcessMessages默认情况下sleep时不会处理其他消息