Board index » delphi » OnActivate doesn't work as advertised? (D3)

OnActivate doesn't work as advertised? (D3)

Declare a global variable 'cnt', initialized to zero:

var
        cnt : ineteger = 0;

Put a label on the main form, and create the form's OnActivate event:

procedure TForm_Main.FormActivate(Sender: TObject);
begin
   inc( cnt );
   label1.Caption := 'Counter: ' + inttostr( cnt );
end;

Now, according to documentation (and what's often repeated said in this
newsgroup), the OnActivate even is supposedly called each time the fiorm
receives focus. The counter should then increment whenever you switch back
to the application, click on it, minimize and maximize it back again, etc.
However, this doesn't happen at all: the counter is incremented ONLY ONCE,
and retains its value of one seemingly forever.

Is it a known bug in D3, or am I missing something?

(Actually I'm sort of happy about it. I was normally initializing my
programs inside OnCreate, but have recently come across a problem with this
approach (some visual elements weren't updated properly). I'd much rather
do all the init stuff in OnActivate, not a good idea according to the docs
unless one keeps a boolean "WasInitialized" kind of variable... OTOH, there
doesn't seem to be a way to perform some operation every tiome the form is
actually brought to font, i.e. when it receives focus. OnShow doesn't do
that either (it's not even called after OnCreate or OnActivate - a counter
like the above stays at zero! Oh well...)

.marek

--
General Frenetics, Discorporated: http://www.lodz.pdi.net/~eristic/
See URL for PGP public key.
If you find yourself in a hole, the first thing to do is stop diggin'.

 

Re:OnActivate doesn't work as advertised? (D3)


I haven't done alot with these, but here goes: There are two OnActivate. A
form's OnActivate is fired when the form receives the application focus, as
far as I know, it does not get fired if you switch to a different
application and back, or if you minimize/maximize the application.  The
Application.OnActivate event is fired when the application receives focus,
i.e. you switch between applications.
Quote
marek jedlinski wrote in message <36a4c8d2.4324...@news.nask.org.pl>...
>Declare a global variable 'cnt', initialized to zero:

>var
> cnt : ineteger = 0;

>Put a label on the main form, and create the form's OnActivate event:

>procedure TForm_Main.FormActivate(Sender: TObject);
>begin
>   inc( cnt );
>   label1.Caption := 'Counter: ' + inttostr( cnt );
>end;

>Now, according to documentation (and what's often repeated said in this
>newsgroup), the OnActivate even is supposedly called each time the fiorm
>receives focus. The counter should then increment whenever you switch back
>to the application, click on it, minimize and maximize it back again, etc.
>However, this doesn't happen at all: the counter is incremented ONLY ONCE,
>and retains its value of one seemingly forever.

>Is it a known bug in D3, or am I missing something?

>(Actually I'm sort of happy about it. I was normally initializing my
>programs inside OnCreate, but have recently come across a problem with this
>approach (some visual elements weren't updated properly). I'd much rather
>do all the init stuff in OnActivate, not a good idea according to the docs
>unless one keeps a boolean "WasInitialized" kind of variable... OTOH, there
>doesn't seem to be a way to perform some operation every tiome the form is
>actually brought to font, i.e. when it receives focus. OnShow doesn't do
>that either (it's not even called after OnCreate or OnActivate - a counter
>like the above stays at zero! Oh well...)

>.marek

>--
>General Frenetics, Discorporated: http://www.lodz.pdi.net/~eristic/
>See URL for PGP public key.
>If you find yourself in a hole, the first thing to do is stop diggin'.

Re:OnActivate doesn't work as advertised? (D3)


Im Artikel <36a4c8d2.4324...@news.nask.org.pl>, eris...@lodz.pdi.net (marek
jedlinski) schreibt:

Quote
>OnShow doesn't do that either

It's a mess with the undocumented order, in that Windows sends notifications
about these events. Even if some Delphi version implements a workaround, this
may not work with future OS versions :-(

IMO the only thing that you can be sure of is, that state or focus changes
between applications, windows and controls are NOT notified as expected :-(

DoDi

Other Threads