[DUG] Forms Activate Design decision

Stacey Verner stacey at cjntech.co.nz
Thu Oct 5 08:13:28 NZDT 2006


We use FormActivate for loading data as well, however we use a guarf
variable to make sure it happened only once.

e.g. 

procedure TForm1.FormCreate(Sender: TObject);
begin
  FFormActivated := False;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  if not FFormActivated then begin
    FFormActivated := True;
    // Do stuff
  end;
end;

We actually have a FirstTimeFormActivate method to override for this
kind of thing in our base form class.

Using FormActivate is great for triggering loading data because it allow
the form to be shown first, and then the data is loaded so the users
know something is going on. If you load data in FormCreate or FormShow
then the screen doesn't show untill all of the daya is loaded.

Stacey


-----Original Message-----
From: delphi-bounces at ns3.123.co.nz [mailto:delphi-bounces at ns3.123.co.nz]
On Behalf Of John Bird
Sent: Wednesday, 04 October 2006 17:53
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG] Forms Activate Design decision

A design question:

FormA (Main form) open all the time.

FormA opens FormB, and FormB filled with Data in On-activate event

FormB may open FormC or FormD for further details

When FormC or FormD is closed, sometimes FormB on-activate event is
fired
again, sometimes not.

I haven't figured yet what decides whether FormB activate event gets
fired
again - as far as I can tell its not whether FormC or FormD is modal or
not.
I would prefer either it wasn't fired, or I could tell when it was going
to
be so as to exit the event, as sometimes the data takes time to load
again.

For instance opening Rave Report rvSystem printing options always does
cause
a form (eg FormB) to get re-activated when it closes.

Is there a way I have missed to manage this?, or do I have to do some
housekeeping, eg
maintain my own state variable somewhere:

FormBLoadedData:Boolean

And in the FormB activate event have something like

	if FormBLoadedData=true then exit;
	LoadtheData;
	FormBLoadedData:=true;

(this will prevent subsequent forms C and D reloading the data on FormB
when
they close)

And on the close event for FormB have

	FormBLoadedData:=false;


John


_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz
http://ns3.123.co.nz/mailman/listinfo/delphi



More information about the Delphi mailing list