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'.