progress.pas

来自「将DataGrid或dxDbGrid或cxGrid或数据集中的数据导出到Exce」· PAS 代码 · 共 81 行

PAS
81
字号
unit Progress;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;

type
  TfmProgress = class(TForm)
    ProgressBar1: TProgressBar;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
  private
    { Private declarations }
  public
    { Public declarations }
    BeginDate: TDatetime;
  end;

var
  fmProgress: TfmProgress;
procedure CreateProgress(Title: string; MaxProgress: integer);
procedure UpdateProgress(Position: integer);
procedure DeleteProgress;
implementation

{$R *.dfm}

procedure CreateProgress(Title: string; MaxProgress: integer);
begin
  if not assigned(fmProgress) then
    fmProgress := TfmProgress.Create(Application);
  fmProgress.Label1.Caption := Title;
  fmProgress.ProgressBar1.Max := MaxProgress;
  fmProgress.ProgressBar1.Position := 0;
  fmProgress.BeginDate := now;
  fmProgress.Show;
end;

procedure UpdateProgress(Position: integer);
var
  Dely1, Pecent1: Double;
  TimeStr: string;
begin
  TimeStr := '';
  if AsSigned(fmProgress) then
  begin
    fmProgress.ProgressBar1.Position := Position;
    Pecent1 := Position / fmProgress.ProgressBar1.Max;
    fmProgress.Label3.Caption := IntToStr(Trunc(Pecent1 * 100)) + '%';
    Dely1 := (now - fmProgress.BeginDate) * 24 / pecent1 * (1 - pecent1);
    if Trunc(Dely1) > 0 then
      TimeStr := TimeStr + IntToStr(Trunc(Dely1)) + '时';
    Dely1 := Frac(Dely1) * 60;
    if Trunc(Dely1) > 0 then
      TimeStr := TimeStr + IntToStr(Trunc(Dely1)) + '分';
    Dely1 := Frac(Dely1) * 60;
    if Trunc(Dely1) > 0 then
      TimeStr := TimeStr + IntToStr(Trunc(Dely1)) + '秒'
    else
      TimeStr := TimeStr + '0秒';
    fmProgress.Label5.Caption := TimeStr;
    fmProgress.Update;
  end;
end;

procedure DeleteProgress;
begin
  if AsSigned(fmProgress) then
  begin
    fmProgress.Free;
    fmProgress := nil;
  end;
end;
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?