Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread EWB 2.02 (?) Startup Timing Issue
Thu, Oct 22 2015 7:19 AMPermanent Link

Mark Brooks

Slikware

Avatar

I am struggling with something that I think should be simple. Create a basic app with a MainForm and a SubForm. Ensure that both are auto-created. I get an exception when I try to access the SubForm from the Mainform in either the MainForm OnCreate or OnShow, both with or without the async keyword mechanism.

I am assuming that SubForm, even though auto-create, has not been created (or its global variable has not been initialised to its instance) at the time when MainForm is created or shown.

So, this begs the question, how do I know when it's "safe" to access SubForm during the app startup process?

FYI, I want to automatically set SubForm's parent to MainForm as part of the app initialisation.

Don't think I've seen this issue before so maybe something has changed?
Thu, Oct 22 2015 7:38 AMPermanent Link

Rick

On 22/10/15 22:19, Mark Brooks wrote:
> FYI, I want to automatically set SubForm's parent to MainForm as part of the app initialisation.
>

You could do something like the following:

1. Turn off auto-create for SubForm.
2. Add SubUnit to uses of MainUnit.
3. Define an OnCreate event for MainForm with the following contents:

SubForm:=TSubForm.Create(Self);

If it doesn't work during MainForm OnCreate then try OnShow.

This should parent SubForm to MainForm and display it within MainForm.

--
Rick
Thu, Oct 22 2015 8:06 AMPermanent Link

Mark Brooks

Slikware

Avatar

Hi Rick

Yup. That'd work for sure. Just a shame that the extra code is required.

Do you also think that something in the startup "timing" has changed in a recent release?

Regards

Mark
Thu, Oct 22 2015 8:26 AMPermanent Link

Rick

On 22/10/15 23:06, Mark Brooks wrote:
> Do you also think that something in the startup "timing" has changed in a recent release?
>

Mark, I think Tim mentioned that the main form variable is now
accessible from its OnCreate event whereas it wasn't before (had to use
"self"). This may have altered something.

You can alter the order in which forms are auto-created by
dragging/dropping them in the Forms tab under Project Options. Maybe you
could set SubForm to be created before MainForm so you know it will be
available.

If MainForm is being created first then I guess you could define a
TSubForm.OnCreate event and set Parent:=MainForm in there.

Not sure how you could do it with less code.

--
Rick
Thu, Oct 22 2015 2:43 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Mark,

<< Do you also think that something in the startup "timing" has changed in a recent release? >>

Nothing has changed in this regard.  It's just a simple matter of X before Y. Smile

Tim Young
Elevate Software
www.elevatesoft.com
Sat, Oct 24 2015 7:53 AMPermanent Link

Mark Brooks

Slikware

Avatar

Tim Young [Elevate Software] wrote:

>> Nothing has changed in this regard.  It's just a simple matter of X before Y. Smile

Ok Tim. Maybe it's me. Just didn't see this in the prior version. No worries.
Image