[Lazarus] Hiding a component by changing its parent

Bart bartjunk64 at gmail.com
Mon Oct 19 20:01:02 CEST 2015


On 10/19/15, Martin Grajcar <maaartinus at gmail.com> wrote:
> On Mon, Aug 24, 2015 at 4:43 PM, Mattias Gaertner
> <nc-gaertnma at netcologne.de
>> wrote:
>
>> On Mon, 24 Aug 2015 16:29:49 +0200
>> Martin Grajcar <maaartinus at gmail.com> wrote:
>>
>> > In code I'm working on, I've found a pattern like
>> >
>> > PROCEDURE HideIt;
>> > BEGIN
>> >   SomeComponent.Visible := FALSE;
>> >   SomeComponent.Parent := SELF;
>> >   SomeComponent.Visible := TRUE;
>> > END;
>> >
>> > PROCEDURE ShowIt(NewParent: TForm);
>> > BEGIN
>> >   SomeComponent.Visible := FALSE;
>> >   SomeComponent.Parent := NewParent;
>> >   ...some more stuff...
>> >   SomeComponent.Visible := TRUE;
>> >   ...some more stuff...
>> > END;
>> >
>> > I can't really see what it's good for. I guess, the idea was to
>> > preserve
>> > the widget, but the widget seems to get freed immediately in the first
>> > line. It comes from D7 or older. Does it make sense on Lazarus 1.4
>> > using
>> > GTK+?
>>
>> No.
>> Simply do "SomeComponent.Parent := NewParent;".
>>
>
> Thank you for the information! Simplifying helped to get rid of a crash on
> Linux
> http://bugs.freepascal.org/view.php?id=28840
> but there's still an event-related problem on Mac. Could someone tell me
> more about what problem may get solved by using the more complicated stuff?
>
> Martin.
>




More information about the Lazarus mailing list