unit LoadingForm;

interface

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

type
  TLoadingFrm = class(TForm)
    DisplayImg: TImage;
    DisplayTimer: TTimer;
    ProgressLbl: TLabel;
    LogRich: TRichEdit;
    procedure DisplayTimerTimer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure FormHide(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  LoadingFrm: TLoadingFrm;
  CurrFrame: word;
  Frames: array[0..16] of TBitmap;

function AddLeading(s:string; needed:word; leading:char='0'):string;

implementation

uses StrUtils;

function AddLeading(s:string; needed:word; leading:char='0'):string;
begin
 Result := DupeString(leading, needed-Length(s))+s;
end;

{$R *.dfm}

procedure TLoadingFrm.DisplayTimerTimer(Sender: TObject);
begin
 if not Visible then exit;
 DisplayImg.Picture.Bitmap := Frames[CurrFrame];
 Inc(CurrFrame);
 if CurrFrame>16 then CurrFrame := 0;
end;

procedure TLoadingFrm.FormCreate(Sender: TObject);
var i:byte;
begin
 DoubleBuffered := true;
 for i := 0 to 16 do begin
  Frames[i] := TBitmap.Create;
  Frames[i].LoadFromFile(
   '.\pdat\loading\frame'+AddLeading(IntToStr(i),3)+'.bmp');
 end;
end;

procedure TLoadingFrm.FormClose(Sender: TObject; var Action: TCloseAction);
var i:byte;
begin
 Action := caNone;
 Hide;
end;

procedure TLoadingFrm.FormShow(Sender: TObject);
begin
 DisplayTimer.Enabled := true;
end;

procedure TLoadingFrm.FormHide(Sender: TObject);
begin
 DisplayTimer.Enabled := false;
end;

end.
