Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-08

Hiding a component by changing its parent

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Grajcar

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+?

Whenever there's a focused TextField in SomeComponent, there's a segment violation on Linux after HideIt. It looks like an event (lost focus?) gets delivered to its already freed widget. Any thoughts? -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150824/2bd324e9/attachment.html>

Reply by email

Mattias Gaertner
to Martin Grajcar
Show quoted text 22 lines
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;".

Mattias

Reply by email

Martin Grajcar
to Mattias Gaertner

On Mon, Aug 24, 2015 at 4:43 PM, Mattias Gaertner <

Show quoted text 31 lines
wrote: On Mon, 24 Aug 2015 16:29:49 +0200 Martin Grajcar 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151019/043a1738/attachment.html>

Reply by email

Bart
to Martin Grajcar
Martin Grajcar wrote 44 lines
On Mon, Aug 24, 2015 at 4:43 PM, Mattias Gaertner < > wrote: > On Mon, 24 Aug 2015 16:29:49 +0200 > Martin Grajcar 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.

Reply by email