{------------------------------------------------------------------------------}
{
   Unit Name: WaitForm
   Purpose  : To show a progressbar
   Author   : Vesa Lappalainen
   Date     : 13.4.2001
   Changed  :

   ToDo     :
}
{------------------------------------------------------------------------------}

unit WaitForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OptionButton, ExtCtrls, ComCtrls;

type
  TFormWait = class(TForm)
    PanelButtons: TPanel;
    Cancel: TOptionButton;
    PanelBar: TPanel;
    ProgressBar: TProgressBar;
    procedure CancelClick(Sender: TObject);
  private
    procedure SetMaxValue(const Value: integer);
    { Private declarations }
  public
    { Public declarations }
    function Inc:boolean;
    procedure ShowValue(i:integer);
  published
    property Value : integer write ShowValue;
    property MaxValue : integer write SetMaxValue;
  end;

function CreateWaitForm(Parent:TWinControl;const text:string; maxvalue:integer=10):TFormWait;

implementation

{$R *.DFM}

function CreateWaitForm(Parent:TWinControl;const text:string; maxvalue:integer):TFormWait;
begin
  Result := TFormWait.Create(Parent);
  Result.PanelButtons.Caption := text;
  Result.ProgressBar.Position := 0;
  Result.ProgressBar.Max := maxvalue;
  Result.Show;
  Application.ProcessMessages;
end;


{ TFormWait }

function TFormWait.Inc : boolean;
begin
  ProgressBar.Position := ProgressBar.Position + 1;
  Application.ProcessMessages;
  Result := Visible;
end;

procedure TFormWait.SetMaxValue(const Value: integer);
begin
  ProgressBar.Max := Value;
end;

procedure TFormWait.ShowValue(i: integer);
begin
  ProgressBar.Position := i;
  Application.ProcessMessages;
end;

procedure TFormWait.CancelClick(Sender: TObject);
begin
  Close;
end;

end.
