I am opening the form as follows:
procedure TScnTest.Stkupd;
var form:TScnMsUpd;
begin form:=TScnMsUpd.create(self);form.ShowModal;form.free;end;
Does anyone have any ideas?
Close does not work unless it is inside a button procedure, EndThread
closes everything, as does EndProcess. STUMPED in Chicago.
Take a look at the OnClose event for your form- try assigning caFree to the
Action. Then call Close. Also, wrap your code in a try.. finally block.
Brian
borland.com
>begin form:=TScnMsUpd.create(self);form.ShowModal;form.free;end;
You are showing modally. Assigning non-zero to ModalResult should be
sufficient. At least that's how it's documented and how it works here.
Throw away those books.
Ciao, MM
--
Marian Aldenhövel, Hainstraße 8, 53121 Bonn, Germany
Tel: +49 228 624013 Fax: +49 228 624031
http://www.gammasoft.de/maier
"Was schiefgehen kann geht schief"
My code in form 2 is extrememly simple:
On Form2Activate
begin
procedure 1: stuffs some strings into several panel.captions
procedure 2: process some text files + display progress in
panel.captions
close; where I want to close the form programatically
end;
Closing the form by using a button or menu works, but I don't want any user
interactions:. the goal is to just close the form unser program control when
file processing is finished and then return to the main form.
My code in form 2 is extrememly simple:
On Form2Activate
begin
procedure 1: //stuffs some strings into several
panel.captions
procedure 2: //process text files, display progress in
panel.captions
modalresult := 3; // where I want to close the form
programatically
end;
I also tried
ModalResult:=mrCancel
also MrCancel to no avail.
Fred, this the root of your problem: you do all this in the forms
OnActivate handler which is executed *before* the modal message loop in
ShowMessage starts to run. There is an assignment ModalResult := mrNone
before the start of this loop and that wipes out your efforts to close the
form.
Replace the assignment to ModalResult with this:
PostMessage( handle, wm_syscommand, sc_close, 0 );
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitely requested!
Should I have done those routines in another handler, such as maybe
OnForm2Display?
Whatever of the form events you use, with one exception (OnPaint) will
execute before the modal message loop starts to run and will have the
same problem. For a task like yours I usually either post a user
message to the form in its onCreate handler and do the processing in
the handler for this message, or use the OnPaint event, like this:
Procedure TFormX.FormPaint;
Begin
OnPaint := Nil; // make sure handler is only called once
Application.ProcessMessages; //make sure all controls are painted
...do stuff
Modalresult := mrOK;
End;
The OnPaint handler is called when the modal message loop is already
running.