Re: [Lazarus] Accessing components in FormCreate event

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Accessing components in FormCreate event

Lars
> No, formcreate is the correct event to set up new components.
> OnShow may be called multiple times in the lifetime of a form.
>
> Michael.

In OnShow I use a counter to only do the change on the first show. I've
even made a FirstShow event years ago.

I trust what you say since you are very experienced in Delphi and Lazarus,
however I could swear that I have been bitten by a bug before where not
all the components on the form are necessarily initialized in FormCreate.
i.e. I could swear that some components, aren't guaranteed to be fully
ready, just because a form is created....  Does the form create guarantee
the componenents are all ready for modification and initialized, because I
could absolutely swear that this has haunted me before where the form
itself is ready and created, but that didn't guarantee the children of the
form were all ready...

So a solution, was to put a counter in FormShow (local const var or
whatever you call those strange things that persist like a global, but are
still local) and access the components on the first show only.

If I could just find one other person that has been haunted by accessing
components in formcreate, then I'd confirm I am not imagining things and
my memory is solid. However, you've been programming far longer so... I am
wanting to trust what you say!
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Accessing components in FormCreate event

Lars
On Thu, September 22, 2016 12:31 am, I previously wrote:
> If I could just find one other person that has been haunted by accessing
> components in formcreate, then I'd confirm I am not imagining things

i.e. here are some issues others have come across which may be semi
related to problems I have experienced, or not:

Quote "However sometimes a few special things can cause problems in
FormCreate, usually related to the order window handles are created, and
for such special cases FormShow can also be abused for initialization. "
-- Jens Grusche, (posted on another delphi list)

And this:
http://stackoverflow.com/questions/3261653/why-would-something-fail-in-formcreate-but-work-fine-in-formshow

However these may be issues with formcreate that are not related to the
bugs I have come across. I'm trying to remember what exactly was the
problem that I had in FormCreate, but can't remember. I do recall having
to create a FirstShow hack to do what I needed to do... I don't like using
the FormShow event, even with a counter, since it is called multiple times
and FormCreate is only called once.
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Accessing components in FormCreate event

Luca Olivetti
El 22/09/16 a les 08:47, Lars ha escrit:

>
> However these may be issues with formcreate that are not related to the
> bugs I have come across. I'm trying to remember what exactly was the
> problem that I had in FormCreate, but can't remember


I don't remember exactly, but the size of the component isn't the final
one (depending on align, anchors or autosize, as I said I don't remeber
the details) until the FormShow, so if you need them to initialize other
components you have to wait.

Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Accessing components in FormCreate event

Lukasz Sokol
On 22/09/16 08:13, Luca Olivetti wrote:

> El 22/09/16 a les 08:47, Lars ha escrit:
>
>>
>> However these may be issues with formcreate that are not related to
>> the bugs I have come across. I'm trying to remember what exactly
>> was the problem that I had in FormCreate, but can't remember
>
>
> I don't remember exactly, but the size of the component isn't the
> final one (depending on align, anchors or autosize, as I said I don't
> remeber the details) until the FormShow, so if you need them to
> initialize other components you have to wait.
>
> Bye

From what I remember (on Turbo Delphi, but this is generally true I think)
anything that causes the form to redraw,
(as it's been indicated in responses here too - resizing, aligning, changing colours etc)
is a really bad idea, because there may not be anything to answer the OnPaint events yet
while FormCreate is being serviced.

(Speculation because I haven't dived that deep: the visual component hierarchy on the form
is kept in a tree-like structure, that is being walked top-down by a single thread,
and so other components' OnCreate is called AFTER their parent is created, and not necessarily
in order of appearance (in order of being placed on form, presumably?)
Whereas in On(First)Show of the main form you can assume the entire tree exists and has sizes and
positions calculated at least once)

Hope it's not overly far from truth ;)

-L.


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Accessing components in FormCreate event

Mattias Gaertner
On Thu, 22 Sep 2016 09:50:06 +0100
Lukasz Sokol <[hidden email]> wrote:

>[...]
> From what I remember (on Turbo Delphi, but this is generally true I think)
> anything that causes the form to redraw,
> (as it's been indicated in responses here too - resizing, aligning, changing colours etc)
> is a really bad idea, because there may not be anything to answer the OnPaint events yet
> while FormCreate is being serviced.

There is no OnPaint during OnCreate.

 
> (Speculation because I haven't dived that deep: the visual component hierarchy on the form
> is kept in a tree-like structure, that is being walked top-down by a single thread,
> and so other components' OnCreate is called AFTER their parent is created, and not necessarily
> in order of appearance (in order of being placed on form, presumably?)

The order of dropping the components on the form defines the creation
order.

>[...]

Mattias
--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus-ide.org/listinfo/lazarus