Hi.
Have you tried Form2.FormShow event?
Otherwise:
Form2.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:= false;
Call_Your_Start_Procedure_Here;
end;
Form2.FormShow(Sender: TObject);
begin
Timer1.Interval:= 100;
Timer1.OnTimer:= @Timer1Timer;
Timer1.Enabled:= true;
end;
This would also do the trick...
HTH
Regards Benny
Yes, I tried form2.formshow event and this is the cause of my current problem with the form not showing :-) The formshow event seems to execute before the form is actually displayed (this is the same behaviour as Delphi though, so not a new feature). This is why I had my code in the formactivate event instead.
To show what I'm trying to do, consider the following simple app:
Create a new app with 2 forms - form1 and form2. On form 1 place a button that executes form2.showmodal. On form2, place a random selection of controls (they don't have to do anything, it's just so you can see if the form has fully painted or not)
Now in the form2.formshow event, put some code, for example 'messagdlg ('hello world',mtinformation,[mbok],0);'
When you click the button on form1, the messagedlg appears. Form2 does not appear. When you close the messagedlg, then form2 appears. I did think at first it just needed some application.processmessages commands before the messagedlg, but these make no difference. However, this behaviour is the same as Delphi, so this would suggest that formshow is not designed to be used for this sort of thing, and that formactivate is the right place for this sort of stuff.
Now, if you put the messagedlg code in the form2.formactivate event instead, then it all displays fine, exactly as it does in Delphi. Yay ! However, there is a big problem in that the formactivate event triggers each time the form gets focus (unlike Delphi which just runs it when the form is first called)
So I can't use formshow because it runs before painting the form, and I can't use formactivate because it runs every time the form gets focus.
I tried the timer suggestion and it works but I don't like using a timer on the form to kick off the code, as this just seems "wrong" to me. The app doesn't "know" that the form has displayed correctly, it just assumes it is as there as the delay is "long enough" for it to have finsihed displaying. Yuk ! :-)
The good news is that I've worked around the strange behaviour of formactivate by wrapping execution of the code around a control variable 'is_running'. I set this variable to false in form1 when the button which executes the form2.showmodal is clicked. The form2.formactivate will only run my code if the value is false, and the first thing the code block does is set it to true. For example:
procedure TForm1.Button1Click(Sender: TObject);
begin
is_running := false ;
form2.showmodal ;
end;
procedure TForm2.FormActivate(Sender: TObject);
begin
if is_running = false then
begin
is_running := true ;
messagedlg ( 'hello world',mtinformation,[mbok],0);
end;
end;
I still don't like that, but it's less of a horrible bodge than using a timer I think.
I wonder if there are any plans to change formactivate to mirror the Delphi mode of operation ?
Edit: Reworded post a bit to make more sense !!