NOTE: the order of startup events for a form are as follows:
1. OnCreate
2. OnShow
3. OnActivate
4. OnPaint
**************************************************************************************
I sometimes do it like this:
procedure TForm1.FormCreate(Sender: TObject);
begin
onShow := FormFirstShow;
end;
procedure TForm1.FormFirstShow(Sender: TObject);
begin
// Do init settings
Form1.OnShow := FormShow;
Form1.OnShow(self);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
// do something else
end;
Here FormFirstShow will only be run once. It often leads to a nicer onShow
method. It also works for many other things, like when you have a PageControl
and a button does diffrent things depending on which page you are on.
**************************************************************************************
Gerald J. Clancy, Jr wrote:
> I usually create a private var, bInitialized,
> initialize it to False in FormCreate and then in FormShow ...
One other way to get this is to have a Timer on the form and
use the event from that as an "AfterShow" event. First thing
the event does is disable the timer, free it and NIL it. Freeing
is not essential but does reduce your use of system resources
(Win95 has only 16 timers AFAIK).
This guarantees that you only execute it once, and also lets the
from become visible before anything slow happens. For instance,
I have one like this in the current project:
procedure TfrmRules.timAfterShowTimer(Sender: TObject);
begin
timAfterShow.Enabled := false;
self.RefreshData;
lstActionNamesSelect(nil);
dbMonitor.OnRuleScroll := self.OnRuleScroll;
end; {TfrmRules.timAfterShowTimer}
That RefreshData call can take 1 or 2 seconds to complete the first
time since it opens database queries and so forth. This way the form
is up and has the SQL hourglass cursor visible while the data loads,
rather than having a locked/non-redrawing parent form while this
one loads.
Moz