发现子程序中调用进度条,有时候会不响应!
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    ProgressBar1: TProgressBar;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
  Procedure ProceBarTest();stdcallimplementation{$R *.dfm}
Procedure ProceBarTest();stdcall
var
  time : Integer;
begin
  Form1.ProgressBar1.Position:=0;
  Form1.ProgressBar1.Max:=30000;
  for time:=0 to 30000 do
  begin
    Form1.ProgressBar1.StepIt;
    Form1.ProgressBar1.Update;
  end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  ProceBarTest;
end;end.
我用的是D7,大家帮我测试下,测试的时候把D7关掉。运行exe,不停刷新桌面试下!

解决方案 »

  1.   

    Procedure ProceBarTest();stdcall
    为什么设置成这样的过程?写到Form1的Private里不行么?写成普通私有函数(过程)么。
      

  2.   

    不知道你说的是什么问题,你指定运动步长了没?STEP?
    ProgressBar1.STEP默认是10,但是你现在明显超过了30000.
      

  3.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        ProgressBar1: TProgressBar;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      Procedure ProceBarTest();stdcallimplementation{$R *.dfm}
    Procedure ProceBarTest();stdcall
    var
      time : Integer;
    begin
      Form1.ProgressBar1.Position:=0;
      Form1.ProgressBar1.Max:=30000;
      for time:=0 to 30000 do
      begin
        Form1.ProgressBar1.StepIt;
        Form1.ProgressBar1.Update;
        Application.ProcessMessage;//讓程序有機會處理其他消息
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      ProceBarTest;
    end;end.
      

  4.   


    如果子程序只是調用這個函數,應該不會沒有響應。如果還在做其它操作,嘗試加一個 application.processMessage;
      

  5.   

    Form1.ProgressBar1.Update;
    后面加一句:
    Application.ProcessMessages;
      

  6.   

    意思就想说D7关掉之后,如果操作很多的话,进度条可能不响应,不用Application.ProcessMessages;这个的,
    大家没有这种现象?奇怪..
      

  7.   

    不可能不用, Application.ProcessMessage 的作用是进入一次消息循环,这样控件才能有机会重绘,否则就一直死等下去,直到过程结束再次进入消息循环