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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoke Process in Form Upon Execution 2

Status
Not open for further replies.

Glenn9999

Programmer
Jun 19, 2004
2,312
US
I've been looking for a good while on how to run a process with a form upon invocation of the form. Basically run the program, the form shows up, the controls get updated, etc.

To clarify, I'm *NOT* talking about anything involving the form events "FormCreate" or "FormShow", because both of these do not fulfill the requirements. Any logic in these events occurs *BEFORE* the form is even shown to the user.

I'm wanting to do something that will be as if the user pressed a button after the form is shown, but will happen immediately upon load.
 
You mean something like Activate? There's an OnActivate event handler for form that you can assign methods to that might be what you're looking for.

Lee
 
Not really. OnActivate would run the code each time the form receives focus (i.e. the user clicks the desktop and then the form again).
 
Just tried it and it seems like it might work. Is there a case where OnActivate would fire in a case other than when the form is first shown?

(Maybe I was getting confused on the documentation when it mentioned MDI child forms?)
 
I've always used OnActivate for apps where I want a process to run immediately, but only once. Create a private boolean variable Activated. Set to false in OnCreate. Then:
Code:
procedure TForm1.FormActivate(Sender: TObject);
begin
  if not Activated then begin
    // do whatever here;
    Activated:= true
  end;
end; //FormActivate


Roo
Delphi Rules!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top