Board index » delphi » MDI App Children Create Error

MDI App Children Create Error

Hi All

I've developed an MDI app by initially using the Delphi Wizard provided.

I then wanted to have a chid window created as the Main app starts up. I
took the default code from the new Button ( CreateMDIChild('NONAME' +
IntToStr(MDIChildCount + 1)); ) and placed it into the Main Form's
FormCreate Method.

When I run the app I get an Error Message :

'Cannot Create Form. No MDI Forms are currently active.'

When I run the code via the default 'New' button click event handler all is
well.

Why is this code not suitable in the FormCreate Event handler?

This error is easily reproducible. Just create the MDI app from the Wizard
and copy the Code from the New button to the FormCreate Handler.

The Child window is, by default, not created by the app via Project Options
"Autocreate Forms" list, but why can I not do it manually?

Thanks
Simon

(Delphi 5 Enterprise)

 

Re:MDI App Children Create Error


Quote
"Simon" <simon.haven...@intec.co.za> wrote in message

news:3b713736_1@dnews...

Quote
> Hi All

> I've developed an MDI app by initially using the Delphi Wizard provided.

> I then wanted to have a chid window created as the Main app starts up. I
> took the default code from the new Button ( CreateMDIChild('NONAME' +
> IntToStr(MDIChildCount + 1)); ) and placed it into the Main Form's
> FormCreate Method.

> When I run the app I get an Error Message :

> 'Cannot Create Form. No MDI Forms are currently active.'

This is because the main form isn't fully created yet until after the Create
method is finished. You should instead post a message to the form in the
Create method and then have the handler of the message create the child
form.

HTH
Woody

Re:MDI App Children Create Error


Quote
"Simon" <simon.haven...@intec.co.za> wrote in message

news:3b713736_1@dnews...

Quote
> Hi All

> I've developed an MDI app by initially using the Delphi Wizard provided.

> I then wanted to have a chid window created as the Main app starts up. I
> took the default code from the new Button ( CreateMDIChild('NONAME' +
> IntToStr(MDIChildCount + 1)); ) and placed it into the Main Form's
> FormCreate Method.

> When I run the app I get an Error Message :

> 'Cannot Create Form. No MDI Forms are currently active.'

> When I run the code via the default 'New' button click event handler all
is
> well.

> Why is this code not suitable in the FormCreate Event handler?

> This error is easily reproducible. Just create the MDI app from the Wizard
> and copy the Code from the New button to the FormCreate Handler.

> The Child window is, by default, not created by the app via Project
Options
> "Autocreate Forms" list, but why can I not do it manually?

check the create  order of your forms. i would suggest moving the
CreateMDIChild routine into the main form's OnShow event and see if that
works.

--
For mad scientists who keep brains in jars, here's a tip: why not add a
slice of lemon to each jar, for freshness?

ICQ: 91418899
http://www.planeted.co.uk
http://www.eduffe.freeserve.co.uk

Re:MDI App Children Create Error


Quote
In article <3b713736_1@dnews>, Simon wrote:
> I've developed an MDI app by initially using the Delphi Wizard provided.

> I then wanted to have a chid window created as the Main app starts up. I
> took the default code from the new Button ( CreateMDIChild('NONAME' +
> IntToStr(MDIChildCount + 1)); ) and placed it into the Main Form's
> FormCreate Method.

Use OnShow or OnActivate, perhaps with an additional test for MDIChildCount =
0. In Oncreate the main forms reference has not yet been assigned to
Application.Mainform, and that is where the childforms look for it.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads