Hi, I''m developing a user interface for querying an SQL database, where controls are being added/deleted dynamically, while the user is working. Everything works just fine when adding controls: you just have to "create" the control, and then call "recalc" for the frame where the control has been added. At some point, I need to delete everything which was added, and start over. This is where I start having problems. Here is some test code, where I tried to reproduce the problem. Add a few controls, delete them all, and add one again: you will see it does not appear at the right place, as if the previous "destroyed" controls where still here, somehow. Does anyone know how to clean all childs of a frame correctly? Best regards! ------------------------------------------------------------- #!/usr/bin/ruby require ''fox16'' include Fox class MyWindow < FXMainWindow def initialize(app) super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 400, 200) stack = FXVerticalFrame.new(self, FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) # Frame where controls are being dynamically added / deleted dynamic_frame = FXHorizontalFrame.new(stack, FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) # Bottom frame for buttons button_frame = FXHorizontalFrame.new(stack, FRAME_NONE|LAYOUT_FILL_X) # Button that adds a control in the dynamic_frame. Works fine. FXButton.new(button_frame, "add").connect(SEL_COMMAND) do |sender, selector, data| FXButton.new(dynamic_frame, "button").create dynamic_frame.recalc end # Button that deletes all child windows of dynamic_frame. # Works, except that afterwards, new controls are not added at the right place. FXButton.new(button_frame, "remove all").connect(SEL_COMMAND) do |sender, selector, data| dynamic_frame.each_child do |child| child.destroy end dynamic_frame.recalc end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 $app = application = FXApp.new("Attik System", "FXRuby Test") MyWindow.new(application) application.create application.run end ------------------------------------------------------------- Attik System web : http://www.attiksystem.ch Philippe Lang phone: +41 26 422 13 75 rte de la Fonderie 2 gsm : +41 79 351 49 94 1700 Fribourg pgp : http://keyserver.pgp.com -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 476 bytes Desc: not available URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/3aabce75/attachment.bin>
Pretty close... Try changing the following code: dynamic_frame.each_child do |child| child.destroy end to: dynamic_frame.each_child do |child| dynamic_frame.removeChild(child) end Seems to work. On Thu, Apr 15, 2010 at 3:31 AM, Philippe Lang <philippe.lang at attiksystem.ch> wrote:> Hi, > > I''m developing a user interface for querying an SQL database, where > controls are being added/deleted dynamically, while the user is working. > > Everything works just fine when adding controls: you just have to "create" > the control, and then call "recalc" for the frame where the control has been > added. > > At some point, I need to delete everything which was added, and start over. > This is where I start having problems. > > Here is some test code, where I tried to reproduce the problem. Add a few > controls, delete them all, and add one again: you will see it does not > appear at the right place, as if the previous "destroyed" controls where > still here, somehow. > > Does anyone know how to clean all childs of a frame correctly? > > Best regards! > > ------------------------------------------------------------- > #!/usr/bin/ruby > > require ''fox16'' > > include Fox > > class MyWindow < FXMainWindow > > def initialize(app) > > super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 400, 200) > > stack = FXVerticalFrame.new(self, > FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) > > # Frame where controls are being dynamically added / deleted > dynamic_frame = FXHorizontalFrame.new(stack, > FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) > > # Bottom frame for buttons > button_frame = FXHorizontalFrame.new(stack, FRAME_NONE|LAYOUT_FILL_X) > > # Button that adds a control in the dynamic_frame. Works fine. > FXButton.new(button_frame, "add").connect(SEL_COMMAND) do |sender, > selector, data| > FXButton.new(dynamic_frame, "button").create > dynamic_frame.recalc > end > > # Button that deletes all child windows of dynamic_frame. > # Works, except that afterwards, new controls are not added at the right > place. > FXButton.new(button_frame, "remove all").connect(SEL_COMMAND) do > |sender, selector, data| > dynamic_frame.each_child do |child| > child.destroy > end > dynamic_frame.recalc > end > > end > > def create > super > show(PLACEMENT_SCREEN) > end > > end > > if __FILE__ == $0 > $app = application = FXApp.new("Attik System", "FXRuby Test") > MyWindow.new(application) > application.create > application.run > end > > ------------------------------------------------------------- > Attik System web : http://www.attiksystem.ch > Philippe Lang phone: +41 26 422 13 75 > rte de la Fonderie 2 gsm : +41 79 351 49 94 > 1700 Fribourg pgp : http://keyserver.pgp.com > > > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-- If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100415/d37fbac3/attachment-0001.html>
Hi, Thanks Joey, your solution works fine. But there is something strange when deleting children of an FXScrollWindow: it always ends up with a SEGMENTION FAULT on my computer. Does anyone have the same problem? You can use the test code below: clicking on the "remove scroll_frame children" button crashes the application. The other 2 buttons work correctly. I suspect a bug in FXRuby of Fox... My config: Windows XP, Ruby 1.8.6 patch level 111, patched FXRuby 1.6.19. ------------------------------------------------------------- #!/usr/bin/ruby require ''fox16'' include Fox class MyWindow < FXMainWindow def initialize(app) super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 400, 150) stack_frame = FXVerticalFrame.new(self, FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) scroll_frame = FXScrollWindow.new(stack_frame, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_SIDE_TOP) matrix_frame = FXMatrix.new(scroll_frame, 10, MATRIX_BY_COLUMNS|LAYOUT_FILL_X|LAYOUT_FILL_Y) (1..17).each do FXButton.new(matrix_frame, "button") end # Bottom frame for buttons button_frame = FXVerticalFrame.new(stack_frame, FRAME_NONE|LAYOUT_FILL_X) # Removes all children from stack_frame container: OK FXButton.new(button_frame, "remove stack_frame children").connect(SEL_COMMAND) do |sender, selector, data| stack_frame.each_child do |child| stack_frame.removeChild(child) end stack_frame.recalc end # Removes all children from stack_frame container: SEGMENTATION FAULT FXButton.new(button_frame, "remove scroll_frame children").connect(SEL_COMMAND) do |sender, selector, data| scroll_frame.each_child do |child| scroll_frame.removeChild(child) end scroll_frame.recalc end # Removes all children from stack_frame container: OK FXButton.new(button_frame, "remove matrix_frame children").connect(SEL_COMMAND) do |sender, selector, data| matrix_frame.each_child do |child| matrix_frame.removeChild(child) end matrix_frame.recalc end end def create super show(PLACEMENT_SCREEN) end end if __FILE__ == $0 $app = application = FXApp.new("Attik System", "FXRuby Test") MyWindow.new(application) application.create application.run end ------------------------------------------------------------- Attik System web : http://www.attiksystem.ch Philippe Lang phone: +41 26 422 13 75 rte de la Fonderie 2 gsm : +41 79 351 49 94 1700 Fribourg pgp : http://keyserver.pgp.com> -----Message d''origine----- > De?: fxruby-users-bounces at rubyforge.org [mailto:fxruby-users- > bounces at rubyforge.org] De la part de Joey Kinsella > Envoy??: jeudi 15 avril 2010 19:42 > ??: fxruby-users at rubyforge.org > Objet?: Re: [fxruby-users] Adding / Deleting controls dynamically > > Pretty close... > > Try changing the following code: > > dynamic_frame.each_child do |child| > child.destroy > end > > to: > dynamic_frame.each_child do |child| > dynamic_frame.removeChild(child) > end > > Seems to work. > > > On Thu, Apr 15, 2010 at 3:31 AM, Philippe Lang > <philippe.lang at attiksystem.ch> wrote: > > > Hi, > > I''m developing a user interface for querying an SQL database, > where controls are being added/deleted dynamically, while the user is > working. > > Everything works just fine when adding controls: you just have to > "create" the control, and then call "recalc" for the frame where the > control has been added. > > At some point, I need to delete everything which was added, and > start over. This is where I start having problems. > > Here is some test code, where I tried to reproduce the problem. > Add a few controls, delete them all, and add one again: you will see it > does not appear at the right place, as if the previous "destroyed" > controls where still here, somehow. > > Does anyone know how to clean all childs of a frame correctly? > > Best regards! > > ------------------------------------------------------------- > #!/usr/bin/ruby > > require ''fox16'' > > include Fox > > class MyWindow < FXMainWindow > > def initialize(app) > > super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 400, 200) > > stack = FXVerticalFrame.new(self, > FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) > > # Frame where controls are being dynamically added / deleted > dynamic_frame = FXHorizontalFrame.new(stack, > FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) > > # Bottom frame for buttons > button_frame = FXHorizontalFrame.new(stack, > FRAME_NONE|LAYOUT_FILL_X) > > # Button that adds a control in the dynamic_frame. Works fine. > FXButton.new(button_frame, "add").connect(SEL_COMMAND) do > |sender, selector, data| > FXButton.new(dynamic_frame, "button").create > dynamic_frame.recalc > end > > # Button that deletes all child windows of dynamic_frame. > # Works, except that afterwards, new controls are not added at > the right place. > FXButton.new(button_frame, "remove all").connect(SEL_COMMAND) > do |sender, selector, data| > dynamic_frame.each_child do |child| > child.destroy > end > dynamic_frame.recalc > end > > end > > def create > super > show(PLACEMENT_SCREEN) > end > > end > > if __FILE__ == $0 > $app = application = FXApp.new("Attik System", "FXRuby Test") > MyWindow.new(application) > application.create > application.run > end > > ------------------------------------------------------------- > Attik System web : http://www.attiksystem.ch > Philippe Lang phone: +41 26 422 13 75 > rte de la Fonderie 2 gsm : +41 79 351 49 94 > 1700 Fribourg pgp : http://keyserver.pgp.com > > > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users > > > > -- > If you are not the intended recipient, you are hereby notified that any > dissemination, distribution, copying or other use of this communication > is strictly prohibited. If you have received this communication in > error, please notify us immediately.-------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 474 bytes Desc: not available URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100419/adf1dc76/attachment.bin>
Am 19.04.2010 11:55, schrieb Philippe Lang:> But there is something strange when deleting children of an FXScrollWindow: it always ends up with a SEGMENTION FAULT on my computer. Does anyone have the same problem? You can use the test code below:Yup, segmentation fault here using your code supplied. Running: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32] on 64bit Win7 FXRuby: fxruby (1.6.16)