Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Closing a form in OnCreate

263 views
Skip to first unread message

Ash Jones

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
In my OnCreate method of my form, I load in an configuration file. if
there's an error in that file I want to be able to tell the user this and
also close the form (i.e. stop using the form).

I placed a CLOSE command but the form still shows. How can I close the form?

thanks

ash


Tim Carthew

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
Hi There Ash

Try this

PostMessage(Handle, WM_CLOSE, 0, 0);

Regards

Tim

Ash Jones <a...@servocon.co.uk> wrote in message news:38fc1cbb@dnews...

Dave Nottage

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
"Ash Jones" <a...@servocon.co.uk> wrote in message news:38fc1cbb@dnews...
> In my OnCreate method of my form, I load in an configuration file. if
> there's an error in that file I want to be able to tell the user this and
> also close the form (i.e. stop using the form).

Why create the form at all if there's an error that means it shouldnt be
shown?

alternatively:
procedure TForm1.FormCreate(Sender: TObject);
begin
MessageDlg('Sorry, you cant continue', mtInformation, [mbOK], 0);
Application.Terminate;
end;

Roger

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
Alternatively, don't create form if there is an error.
In the .DPR file check for an error, if there is an error
don't create the form.
Roger

Ash Jones wrote:

> In my OnCreate method of my form, I load in an configuration file. if
> there's an error in that file I want to be able to tell the user this and
> also close the form (i.e. stop using the form).
>

> I placed a CLOSE command but the form still shows. How can I close the form?
>
> thanks
>
> ash

--
You can't fight in here gentlemen, this is the War Room!
Dr Strangelove

Andrew Porter

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
On Tue, 18 Apr 2000 09:35:40 +0100, "Ash Jones" <a...@servocon.co.uk>
wrote:

>In my OnCreate method of my form, I load in an configuration file. if
>there's an error in that file I want to be able to tell the user this and
>also close the form (i.e. stop using the form).
>
>I placed a CLOSE command but the form still shows. How can I close the form?

One way is to send the form a WM_CLOSE message using postmessage.

Carlos Tré

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
Ash,

Instead of creating an OnCreate method, I'd override its constructor and
abort the creation if the error condition arises.

HTH,
Carlos

Ash Jones <a...@servocon.co.uk> wrote in message news:38fc1cbb@dnews...

> In my OnCreate method of my form, I load in an configuration file. if
> there's an error in that file I want to be able to tell the user this and
> also close the form (i.e. stop using the form).
>
> I placed a CLOSE command but the form still shows. How can I close the
form?
>

> thanks
>
> ash
>
>


Kevin Morris

unread,
Apr 19, 2000, 3:00:00 AM4/19/00
to
Try moving your error detection code to the form's OnShow procedure.
The Close command should work OK from there.


Andrew Porter

unread,
Apr 20, 2000, 3:00:00 AM4/20/00
to
On 19 Apr 2000 14:06:15 -0800, "Kevin Morris" <morr...@spar.ca>
wrote:

>Try moving your error detection code to the form's OnShow procedure.
>The Close command should work OK from there.
>

_My_ error detection code ?

Andrew Gabb

unread,
Apr 23, 2000, 3:00:00 AM4/23/00
to Ash Jones
Ash Jones wrote:
> In my OnCreate method of my form, I load in an configuration file. if
> there's an error in that file I want to be able to tell the user this and
> also close the form (i.e. stop using the form).

The message approach is one way. I prefer a timer which you start
with a very short delay to close the form. Works like a charm.

Andrew
--
Andrew Gabb
email: ag...@tpgi.com.au Adelaide, South Australia
phone: +61 8 8342-1021, fax: +61 8 8269-3280
-----

0 new messages