Board index » delphi » OnActivate Close not closing

OnActivate Close not closing

I have a form that I want to come up, display some progress, then close
after it's finished.  I have discovered that I need to put my code in the
"OnActivate" event of the form so it will proceed with the "visual display".
But, when it's done, I want to display a message like "Process Complete",
and after the user presses the OK button, close the form.  Here is a sample
of the code:

procedure TMyForm.FormActivate(Sender: TObject);
begin
   {process something here}

   MessageDlg('Process Complete!',mtInformation,[mbOK],0);
   Close;
end;

But, the "Close" doesn't close.  After pressing the OK button on the
message, I have to press the "X" button on the form to close it.

I'm using Delphi 1.  Is there some other place I need to be putting this
code? or some other way I need to close when I'm finished.

Thanks,
Jesse

 

Re:OnActivate Close not closing


Quote
"Jesse Castleberry" <D...@iThink.net> wrote:
>I have a form that I want to come up, display some progress, then close
>after it's finished.  I have discovered that I need to put my code in the
>"OnActivate" event of the form so it will proceed with the "visual display".
>But, when it's done, I want to display a message like "Process Complete",
>and after the user presses the OK button, close the form.  Here is a sample
>of the code:

>procedure TMyForm.FormActivate(Sender: TObject);
>begin
>   {process something here}

>   MessageDlg('Process Complete!',mtInformation,[mbOK],0);
>   Close;
>end;

>But, the "Close" doesn't close.  After pressing the OK button on the
>message, I have to press the "X" button on the form to close it.

>I'm using Delphi 1.  Is there some other place I need to be putting this
>code? or some other way I need to close when I'm finished.

>Thanks,
>Jesse

Try this code from your main form:

MyForm.Show; { Or ShowModal }
MyForm.DoProcessing; { Public procedure in TMyForm }
MessageDlg( ... );
MyForm.Close;

Hope this helps,
Jeffrey

Re:OnActivate Close not closing


Quote
>MyForm.Show; { Or ShowModal }
>MyForm.DoProcessing; { Public procedure in TMyForm }
>MessageDlg( ... );
>MyForm.Close;

Problem with this is I have to make this a Modal Box.  So, as soon as I do a
"ShowModal", something
  must happen to close the box before it could do the "myform.doprocessing".
So, this wouldn't work. (I've already tried it).

jesse

Re:OnActivate Close not closing


  So you do as the poster suggested and use show, not show modal...

  However, (if I understand what you're trying to do), a BETTER way is to
show your dialog (so the 'calling form' may continue processing), is to
disable the bottom (calling form) using:

    EnableWindow(Handle, False)+ADs-
    SetWindowPos(MyDialog.Handle, HWND+AF8-TOPMOST, 0, 0, 0, 0, SWP+AF8-NOMOVE or
SWP+AF8-NOSIZE)+ADs-

  and continue processing....

--
Jason Wallace
SL Software
DarkElf+AEA-SLSoftware.reno.nv.us
--
+ACI-We are Microsoft.  Resistance is Futile.  You will be Assimiliated.+ACI-

Quote
Jesse Castleberry wrote in message +ADw-6jvbe0+ACQ-mm0+ACQ-1+AEA-news10.ispnews.com+AD4-...

+AD4APg-MyForm.Show+ADs- +AHs- Or ShowModal +AH0-
+AD4APg-MyForm.DoProcessing+ADs- +AHs- Public procedure in TMyForm +AH0-
+AD4APg-MessageDlg( ... )+ADs-
+AD4APg-MyForm.Close+ADs-
+AD4APg-
+AD4-
+AD4-
+AD4-Problem with this is I have to make this a Modal Box.  So, as soon as I do
a
+AD4AIg-ShowModal+ACI-, something
+AD4-  must happen to close the box before it could do the
+ACI-myform.doprocessing+ACI-.
+AD4-So, this wouldn't work. (I've already tried it).
+AD4-
+AD4-jesse
+AD4-

Re:OnActivate Close not closing


In article <6jvbe0$mm...@news10.ispnews.com>,
  "Jesse Castleberry" <D...@iThink.net> wrote:

Quote

> >MyForm.Show; { Or ShowModal }
> >MyForm.DoProcessing; { Public procedure in TMyForm }
> >MessageDlg( ... );
> >MyForm.Close;

> Problem with this is I have to make this a Modal Box.  So, as soon as I do a
> "ShowModal", something
>   must happen to close the box before it could do the "myform.doprocessing".
> So, this wouldn't work. (I've already tried it).

        ??? You originally said

"I have a form that I want to come up, display some progress, then close
after it's finished."

If you want the form to close itself then why are you using
ShowModal instead of Show? You use ShowModal to show a form
and have it close when the user clicks on something, not a
form that closes itself.

David c. Ullrich

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

Re:OnActivate Close not closing


On Tue, 19 May 1998 13:25:12 -0400, "Jesse Castleberry"

Quote
<D...@iThink.net> wrote:
>I have a form that I want to come up, display some progress, then close
>after it's finished.  I have discovered that I need to put my code in the
>"OnActivate" event of the form so it will proceed with the "visual display".
>But, when it's done, I want to display a message like "Process Complete",
>and after the user presses the OK button, close the form.  Here is a sample

[...]

Indeed you cannot close the form from the OnActivate event. If you
need the form to be modal, the way out I would suggest is to add a
TTimer tou your form, set it initially disabled with a 1 milisecond
interval, and put the Close into the OnTimer.
Then, in your OnActivate, just replace the currently inoperative Close
by Timer1.Enabled := True, this will close the form.

Pierre Gemis

Other Threads