Link to home
Start Free TrialLog in
Avatar of johnclarke
johnclarke

asked on

Formless application

I want to create an application that does not have a form.  However,  I want it to make use of the Timer component so that when a certain time is reached it displays a message to the user.  How can this be done ?

I would be grateful for any advice offered regarding this.

John Clarke
ASKER CERTIFIED SOLUTION
Avatar of williams2
williams2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnclarke
johnclarke

ASKER

I tried this in Delphi 1 and unfortunately it does not work.

John
You are a most Generous guy mr. John Clarke, so I think I'll provide you with an example:

You'll just have to open Delphi, DoubleClick the OnCreate event of Form1, and then cut'n'paste the following lines into unit1:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Timer: TTimer;
    procedure OnTimer(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer:= TTimer.Create(Self);
  Timer.OnTimer:= OnTimer;
  Timer.Interval:= 10000;
  Timer.Enabled:= True;
  Application.ShowMainForm:= False;
end;

procedure TForm1.OnTimer(Sender: TObject);
begin
  If MessageDlg('Every ten seconds!, should I close now?',
                mtInformation,
                [mbYes,mbNo],
                0)=id_Yes
  Then Application.Terminate;
end;

end.
You are a most Generous guy mr. John Clarke, so I think I'll provide you with an example:

You'll just have to open Delphi, DoubleClick the OnCreate event of Form1, and then cut'n'paste the following lines into unit1:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    Timer: TTimer;
    procedure OnTimer(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer:= TTimer.Create(Self);
  Timer.OnTimer:= OnTimer;
  Timer.Interval:= 10000;
  Timer.Enabled:= True;
  Application.ShowMainForm:= False;
end;

procedure TForm1.OnTimer(Sender: TObject);
begin
  If MessageDlg('Every ten seconds!, should I close now?',
                mtInformation,
                [mbYes,mbNo],
                0)=id_Yes
  Then Application.Terminate;
end;

end.
Hmmm.. some error happened above, eh? ..What is the error saying?
Hmmm.. some error happened above, eh? ..What is the error saying?
Hmmm.. some error happened above, eh? ..What is the error saying?
ok, this is a hack! Try it with the forms OnPaint event, or at least after the window is stopped showing (Not OnShow!)

procedure TForm1.FormPaint(Sender: TObject);
begin
  Hide;
end;