[Gambas-user] How do I delete a control on scrollview the correct way?

Benoit Minisini gambas at ...1...
Tue Jun 6 19:07:04 CEST 2006


On Tuesday 06 June 2006 08:53, Ron Onstenk wrote:
> on the forma  Scrollview1 as SVFrames
>
> public function wsadd()
>   fra = NEW Frame(SVFrames) AS "WSfra"
>   lbl = NEW Label(fra)
>   btn = NEW button(fra)
>   tgb = NEW ToggleButton(fra)
>   lv = NEW ListView(fra) AS "WStbl"
> end
>
>
> public wsdel(fra as frame)
>   PRINT "fra.id="; fra.Id
> PRINT "children.count="; fra.Children.Count ' =4
>   FOR EACH ct IN fra.Children 'remove controls from frame
>     ct.Delete  '<--- does not work
>   NEXT
>   fra.Delete  '<--- does not work
> PRINT "children.count="; fra.Children.Count 'is still 4
>
>   fra.Enabled = FALSE
>   showfra
> end
>
>
> for both prints I get 4 children. More stupid is the second print.
> If the frame.delete is done it can't have children anymore.
>
> In the scrollview the count of frames add with wsadd
> stay the same after delete.
> It only grows with wsadd but never lower with wsdel.
>
> in showfra is the next WsTableGetFra used
> after wsdel has run the frame is not visible anymore
> but it is also not realy go to nothing
>
>
> PUBLIC FUNCTION WsTableGetFra() AS Object[]
>   DIM ctl AS Control
>   DIM fra AS Frame
>   DIM objs AS NEW Object[]
>
>   FOR EACH ctl IN SVFrames.Children
>     IF object.Type(ctl) = "Frame" THEN
>       fra = ctl
> PRINT "fra "; fra.tag <----- not changed after delete
>
>       IF object.IsValid(fra) THEN  '<--- stay valid after fra.delete
> PRINT "isValid "; fra.tag 'always
>
>         IF NOT IsNull(fra) THEN '<--- should be null but isn't
> PRINT "NOT IsNull "; fra.tag    '<------never
> PRINT "children.count="; fra.Children.Count '<--- stay at 4
>           IF fra.Enabled THEN objs.Add(fra)
>         ENDIF
>       ENDIF
>     ENDIF
>   NEXT
>
> end
>
> I have only a workaround with the frame.enabled but this
> should be imposible.
>
> Someone a tip what is wrong?
>
> Ron
>
>

Object deletion are deferred: they are executed later, at the return of the 
event loop. I did that because Qt, and other toolkits, do not like deleting a 
control anywhere (especially inside an event handler).

If you want to see the deletion immediately, you can add WAIT just after the 
call to the Delete method.

Regards,

-- 
Benoit Minisini




More information about the User mailing list