[Gambas-devel] Another extrange thing

Benoit Minisini gambas at ...1...
Thu Jun 3 23:15:36 CEST 2004


On Thursday 03 June 2004 18:58, Daniel Campos wrote:
> Hi:
>
> Create a Form with two buttons, and add the following code:
>
> PRIVATE P AS Menu
> PRIVATE Q AS Menu
>
> PUBLIC SUB Button1_Click()
>
>   DIM R AS Menu
>
>   P=NEW Menu(ME)
>   Q=NEW Menu(P)
>   R=NEW Menu(Q)
>   P.Text="ONE"
>   Q.Text="TWO"
>   R.Text="THREE"
>
> END
>
> PUBLIC SUB Button2_Click()
>
>   Message.Info(P.Children.Count)
>   P.Children.Clear
>   Message.Info(P.Children.Count)
>
> END
>
> First, press the 'Button1' a Menu is created:
>
> ---------------------
>
> |  One              |
> |
> |  Two - three      |
>
> ---------------------
>
> Note that 'Two' has a child. Then press 'Button2', the sequence is
> "one child" - clearing - "one child", I think it should report
> just "0 children'
>
>
> But now try that code, in which 'Q' is a local variable:
>
> PUBLIC SUB Button1_Click()
>
>   DIM Q AS Menu
>   DIM R AS Menu
>
>   P=NEW Menu(ME)
>   Q=NEW Menu(P)
>   R=NEW Menu(Q)
>   P.Text="ONE"
>   Q.Text="TWO"
>   R.Text="THREE"
>
> END
>
> PUBLIC SUB Button2_Click()
>
>   Message.Info(P.Children.Count)
>   P.Children.Clear
>   Message.Info(P.Children.Count)
>
> END
>
> press 'Button1', then press 'Button2', the sequence is
> "one child" - clearing - "0 children".
>
> This is too confusing...  Why you add a reference to a local variable,
> but you change the children count in both cases?
>
> I suppose you add a reference because the menu is a child of another
> control,but 'children' count is different!
>
> And what happened with 'R' in both cases?
>
> Regards,

Hmmm... Very strange, I must admit :-) I think this is the same problem as 
before, because P.Children.Clear do many deletes.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list