unit ProgressForm;

interface

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

type
  TProgressForm2 = class(TNonModalForm)
    Label2: TLabel;
    LabelNow: TLabel;
    LabelPercent: TLabel;
    ButtonOK: TButton;
    ButtonStop: TButton;
    ProgressBar: TProgressBar;
    procedure OnClose(Sender: TObject; var Action: TCloseAction);
    procedure ButtonOKClick(Sender: TObject);
    procedure ButtonStopClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure CountNew;
  public
    FAll       : Integer;
    FNow       : Integer;
    boolProcessStoped : Boolean;
    procedure SetAll(i: Integer);
    procedure SetNow(i: Integer);
    procedure Go;
    procedure Stop;
    { Public declarations }
  end;

{
var
  ProgressForm: TProgressForm;

{
procedure ShowProgressForm;
procedure HideProgressForm;
}

implementation

{$R *.DFM}

{
procedure ShowProgressForm;
begin
	if not Assigned(ProgressForm) then
		ProgressForm := TProgressForm.Create(Application);
	if not ProgressForm.Visible then
		ProgressForm.Show;
end;
procedure HideProgressForm;
begin
	if not Assigned(ProgressForm) then
		ProgressForm := TProgressForm.Create(Application);
	ProgressForm.Hide;
end;
}
procedure TProgressForm2.Go();
begin
  ButtonStop.Enabled := True;
  ButtonOk.Enabled := False;
  boolProcessStoped := False;
end;


procedure TProgressForm2.SetAll(i: Integer);
begin
   FAll := i;
   SetNow(0);
   ProgressBar.Min := 0;
   ProgressBar.Max := FAll;
   CountNew;
end;

procedure TProgressForm2.SetNow(i: Integer);
begin
   FNow := i;
   CountNew;
end;

procedure TProgressForm2.CountNew;
begin
  LabelNow.Caption := IntToStr ( FNow ) + ' / ' + IntToStr ( FAll );
  LabelPercent.Caption := IntToStr ( (FNow*100) div FAll ) + ' %';
  ProgressBar.Position := FNow;
  Refresh;
end;


procedure TProgressForm2.OnClose(Sender: TObject; var Action: TCloseAction);
begin
  action := caHide;
end;

procedure TProgressForm2.ButtonOKClick(Sender: TObject);
begin
  Close;
end;

procedure TProgressForm2.ButtonStopClick(Sender: TObject);
begin
  Stop;
end;

procedure TProgressForm2.FormCreate(Sender: TObject);
begin
  ButtonOK.Enabled := False;
end;

procedure TProgressForm2.Stop;
begin
  boolProcessStoped := True;
  ButtonStop.Enabled := False;
  ButtonOk.Enabled := True;
end;

end.



