我现在想做一个转数据的程序,在转数据的同时,提示一个进度条,应该如何做,有没有相关的代码,谢谢!

解决方案 »

  1.   

    做一个Form(waitform),放上进度条(pb_step).
    waitform.show;
    waitform.update;
    while 循环控制 do
    begin
      pb_step.stepit;
      Application.ProcessMessages;
      控制循环   
    end;
    waitform.close;窗体有模式窗体和非模式窗体.show是将窗体以非模式窗体显示,这时你可以做其他事.
      

  2.   

    简单示例pas内容:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, ComCtrls;type
      TForm1 = class(TForm)
        ProgressBar1: TProgressBar;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;  TThreadProgress = class(TThread)
      private
        { Private declarations }
        procedure update;
      protected
        procedure Execute; override;
      public
        constructor create;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      TThreadProgress.create;
    end;{TThreadProgress}
    constructor TThreadProgress.create;
    begin
      FreeOnTerminate:=true;
      inherited create(false);
    end;procedure TThreadProgress.update;
    begin
      form1.ProgressBar1.Position:=form1.ProgressBar1.Position+1;
    end;procedure TThreadProgress.Execute;
    begin
      { Place thread code here }
      while form1.ProgressBar1.Position<form1.ProgressBar1.Max do
      begin
        Synchronize(update);
        sleep(10);
      end;
    end;end.dfm:object Form1: TForm1
      Left = 222
      Top = 159
      Width = 352
      Height = 262
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object ProgressBar1: TProgressBar
        Left = 72
        Top = 72
        Width = 209
        Height = 17
        TabOrder = 0
      end
      object BitBtn1: TBitBtn
        Left = 128
        Top = 136
        Width = 75
        Height = 25
        Caption = 'BitBtn1'
        TabOrder = 1
        OnClick = BitBtn1Click
      end
    end