Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a Please Wait Dialogue... or at least trying to

Status
Not open for further replies.

mobiusonline

IS-IT--Management
Feb 15, 2007
2
I am working on a piece of software that needs to do the following.

When i click button, it opens a form saying "Please Wait, blah blah blah..." over top of the main program (no user interface visible, needs to stay open).

once the form is opened, it opens a batch script (filename.bat) that runs hidden from the user.

once the batch script (filename.bat) closes (times can vary from 10 seconds, to 10 minutes), a message saying it completed successfully, the form disappears, then focus is given back to the main program.

Anyone know how to do this. If anyone can help me, I would be appreciated. I am just tired of going in circles.

Thanks,

M
 
Here is a unit I use for this. I've striped out what you don't need that would just be confusing without explanation.
Important to note that it has a mechanism built in to allow stacked (but hidden) messages. You'll see what I mean if you play with it. Basically, if a message is being displayed, and another is sent, it hides the current one until the second (or 3rd, 4th...) is removed from the stack.

Example usage:
Code:
  EventWaitShow('Creating report: ' + DataMod3.pCurrentOrder, false); //1st
  try
    CreateReport;
    EventWaitShow('Loading orders, false); //2nd
    LoadOrders;
  finally
    EventWaitHide;  //kill 2nd
  end;
  EventWaitHide;  //kill 1st
Heres the form:
Code:
object WaitForm: TWaitForm
  Left = 371
  Top = 236
  ActiveControl = WaitPanel
  BorderIcons = []
  BorderStyle = bsNone
  ClientHeight = 82
  ClientWidth = 547
  Color = clBtnFace
  DefaultMonitor = dmMainForm
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = False
  Position = poScreenCenter
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object WaitPanel: TPanel
    Left = 0
    Top = 0
    Width = 547
    Height = 82
    Align = alClient
    AutoSize = True
    BevelInner = bvLowered
    BevelWidth = 2
    Color = clInfoBk
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 0
    OnClick = WaitPanelClick
  end
end
Here's the unit code:
Code:
unit EventLog;
{$D-}

interface

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

type
  TWaitForm = class(TForm)
    WaitPanel: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure WaitPanelClick(Sender: TObject);
  private
    { Private declarations }
    MsgList: TStringList;
  public
    { Public declarations }
  end;

procedure EventLogger(const amessage: string);
function EventDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
procedure EventWaitShow(const amessage: string; Log: boolean);
procedure EventWaitHide;
procedure EventWaitHideAll;
procedure EventWaitShowOnly;
procedure EventWaitHideOnly;

implementation

{$R *.DFM}

var
  WaitForm: TWaitForm;

//------------------------------ eventlog ----------------------------------------//

procedure EventLogger(const amessage: string);
var
  Header: string;
  s: string;
begin
  s:= amessage;
  Header:= FormatDateTime('MM/DD/YY HH:NN:SS ', Now);
  s:= StringReplace(s, #13, #32, [rfReplaceAll]);
  //WriteToLogFile(s)
end;

function EventDlg(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint): Word;
begin
  EventLogger(Msg);
  EventWaitHideOnly;
  result:= MessageDlg(Msg, DlgType, Buttons, HelpCtx);
  EventWaitShowOnly;
end;

//----------------------------- TWaitForm ------------------------------------/

procedure TWaitForm.FormCreate(Sender: TObject);
begin
  MsgList:= TStringList.Create;
  FormStyle:= fsStayOnTop;
end;

procedure TWaitForm.FormDestroy(Sender: TObject);
begin
  MsgList.Free
end;

//------------------------------ event wait ----------------------------------------//

procedure EventWaitShowOnly;
begin
  if WaitForm <>nil then WaitForm.Show;
end;

procedure EventWaitHideOnly;
begin
  if WaitForm <>nil then WaitForm.Hide;
end;

procedure EventWaitShow(const amessage: string; Log: boolean);
begin
  if WaitForm = nil then WaitForm:= TWaitForm.Create(nil); // else WaitForm.Hide;
  with WaitForm do begin
    MsgList.Add(aMessage);
    WaitPanel.Caption:= aMessage + ', please wait...';
    WaitPanel.Refresh;
    Show;
    Update;
  end;
  if Log then
    EventLogger(amessage)
end; //EventWaitShow

procedure EventWaitHide;
begin
  if WaitForm <> nil then
    with WaitForm do begin
      if MsgList.Count <> 0 then
        MsgList.Delete(MsgList.Count -1);
      if MsgList.Count <> 0 then begin
        WaitPanel.Caption:= MsgList.Strings[MsgList.Count -1] + ', please wait...';
        WaitPanel.Refresh;
      end else
        FreeAndNil(WaitForm)
    end
end;

procedure EventWaitHideAll;
begin
  repeat EventWaitHide until WaitForm = nil
end;

procedure TWaitForm.WaitPanelClick(Sender: TObject);
begin
  Hide;
  Sleep(1000);
  Show
end;

initialization
begin
  WaitForm:= nil;
end;

end.
Let me know if it filled the bill!


Roo
Delphi Rules!
 
As a side note any program that takes the focus away from the program that I am currently working with without my permission is immediately uninstalled and I ensure that my recommendations for that program are - how can I put this politely? - unpleasant.

[vampire][bat]
 
Not sure what you mean... my example is a unit to add to your program build and call as needed.

Roo
Delphi Rules!
 
I'm thinking this should be straight-forward. Build the form with a single label centered in it (and adjusts position according to the size of the label, unless you want the message to word-wrap). Let the form not have any controls on it (bsNone).

In the OnCreate part, put the code that you use to run the bat file (ShellExec), along with a wait cycle, and then when it completes close the form.

Seems straight forward enough to do. What's the problem you are experiencing, mobiusonline?
 
roo0047 I was replying to the OP from whom I quote:

over top of the main program (no user interface visible, needs to stay open).


... which is behaviour in a program that I will not tolerate.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top