[Gambas-devel] Another extrange thing

Daniel Campos danielcampos at ...45...
Thu Jun 3 18:58:45 CEST 2004


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,

-- 
Daniel Campos <danielcampos at ...45...>





More information about the Devel mailing list