Board index » delphi » running a proc after idle?

running a proc after idle?

Hi all,

What is the simplest solution if I want to run a procedure after
the application has returned into its main loop?

I figured out that if I create a hided button, and assign the
proc to its OnClick method, then I can use the PostMessage()
function. Is there a simpler solution?

Thx:
Circum

PS: please cc. to my mailto:eng...@all.hu address too, as I have
some problem with my news server... :( Thx.

 

Re:running a proc after idle?


Quote
"Ferenc Engard" <eng...@all.hu> wrote in message

news:39214CF3.EE77F08E@all.hu...

Quote
> Hi all,

> What is the simplest solution if I want to run a procedure after
> the application has returned into its main loop?

> I figured out that if I create a hided button, and assign the
> proc to its OnClick method, then I can use the PostMessage()
> function. Is there a simpler solution?

You could define your own message and handler for it:

const
    myMessageNo = WM_USER + 1;

type

tForm1 = class (tForm)
    private
        procedure HandleMyMessage (var aMsg : tMessage); message
myMessageNo;
    . . .
    end;

procedure tForm1.HandleMyMessage (var aMsg : tMessage);

begin
. . .
end;

. . .
PostMessage (HandleOfTheFormInstance, myMessageNo, 0, 0);
. . .

Quote

> Thx:
> Circum

> PS: please cc. to my mailto:eng...@all.hu address too, as I have
> some problem with my news server... :( Thx.

Re:running a proc after idle?


I use the following code if I want to do something after a form has been
created.

ps. You can also use the Application.OnIdle.

--- Example ---

const
  wm_AfterCreate = wm_User;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    ...
  private
    { Private declarations }
    procedure WMAfterCreate(var Msg: TMsg); message wm_AfterCreate;
    ...
  public
    { Public declarations }
    ...
  end;

...

procedure TForm1.FormCreate(Sender: TObject);
begin
  ...
  PostMessage(Handle, wm_AfterCreate, 0, 0);
end;

procedure TForm1.WMAfterCreate(var Msg: TMsg);
begin
  // Do stuff after the form is created
end;

"Ferenc Engard" <eng...@all.hu> schreef in bericht
news:39214CF3.EE77F08E@all.hu...

Quote
> Hi all,

> What is the simplest solution if I want to run a procedure after
> the application has returned into its main loop?

> I figured out that if I create a hided button, and assign the
> proc to its OnClick method, then I can use the PostMessage()
> function. Is there a simpler solution?

> Thx:
> Circum

> PS: please cc. to my mailto:eng...@all.hu address too, as I have
> some problem with my news server... :( Thx.

Other Threads