🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.language.objectpascal
Article #32430

Re: Delay in Formless GUI application

#32430
From: Brain Cell
Date: Fri, 22 Nov 2002 19:58
88 lines
2710 bytes
"David B. Ferguson" <david.mcs@ns.sympatico.ca> wrote in news:3dde4d3a$1
@newsgroups.borland.com:

> 
> procedure Delay(MilliSecs: Integer);
> var x:: LongInt;
> begin
>    x:=GetTickCount;
>    repeat
>       Application.ProcessMessages;
>    until ((GetTickCount-x) >= Longint(MilliSecs));
> end;
> 
> 

Try this:

program Project1;

uses
  Windows,
  Messages,
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

{ TMyTimer }
type
  TMyTimer = class
  private
    FWindowHandle: HWND;
    procedure WndProc(var Msg: TMessage);
    procedure StartTimer;
  public
    constructor Create;
    destructor Destroy; override;
  end;

constructor TMyTimer.Create;
begin
  FWindowHandle := AllocateHWnd(WndProc);
end;

procedure TMyTimer.WndProc(var Msg: TMessage);
begin
  with Msg do
  begin
    if Msg = WM_TIMER then
      try
        Application.Initialize;
        Application.CreateForm(TForm1, Form1);
        Application.Run;
        Free;
      except
        Application.HandleException(Self);
      end
    else
      Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
  end;
end;

procedure TMyTimer.StartTimer;
begin
  if SetTimer(FWindowHandle, 1, 60000, nil) = 0 then {60000=60 seconds}
    Application.Terminate;
end;

destructor TMyTimer.Destroy;
begin
  DeallocateHWnd(FWindowHandle);
end;

begin
  With TMyTimer.Create do
  begin
    StartTimer;
  end;
  repeat
    Application.HandleMessage;
  until Application.Terminated;
end.


-- 
I hope this helps,

Brain Cell
Technical Details
Message-ID: <Xns92CE98469A037braincell98yahoocom@207.105.83.65>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!38.144.126.76.MISMATCH!feed2.newsreader.com!newsreader.com!newshosting.com!news-xfer1.atl.newshosting.com!news.stealth.net!news.stealth.net!208.184.7.66.MISMATCH!newsfeed1.cidera.com!Cidera!news.uni-x.net!newsgroups.borland.com!not-for-mail
References: <j3irtukg6568s7q0ishs57vmrng5g284ra@4ax.com> <3dddd21f$1@newsgroups.borland.com> <3dddd953@newsgroups.borland.com> <5iortus03ebeqon39u1gi80k51kcog08dr@4ax.com> <3dde4d3a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d30,78305e78c1df1611
X-Google-Attributes: gid109d30,public
X-Google-ArrivalTime: 2002-11-22 12:15:40 PST
Newsgroups: borland.public.delphi.language.objectpascal
Subject: Re: Delay in Formless GUI application
From: Brain Cell <brain_cell_98@yahoo.com>
References: <j3irtukg6568s7q0ishs57vmrng5g284ra@4ax.com> <3dddd21f$1@newsgroups.borland.com> <3dddd953@newsgroups.borland.com> <5iortus03ebeqon39u1gi80k51kcog08dr@4ax.com> <3dde4d3a$1@newsgroups.borland.com>
Message-ID: <Xns92CE98469A037braincell98yahoocom@207.105.83.65>
User-Agent: Xnews/5.03.24
NNTP-Posting-Host: 12.247.109.100
Date: 22 Nov 2002 11:58:29 -0800
X-Trace: newsgroups.borland.com 1037995109 12.247.109.100 (22 Nov 2002 11:58:29 -0800)
Lines: 88
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!38.144.126.76.MISMATCH!feed2.newsreader.com!newsreader.com!newshosting.com!news-xfer1.atl.newshosting.com!news.stealth.net!news.stealth.net!208.184.7.66.MISMATCH!newsfeed1.cidera.com!Cidera!news.uni-x.net!newsgroups.borland.com!not-for-mail