[Gambas-user] Removing a runtime created control

KKing kicking177 at gmail.com
Fri Nov 27 11:34:43 CET 2020


I've just run the following code in 3.12.2 on Debian10 LXDE and Debian10 
KDE.
NB I'm creating as just "Graphical Application" (i.e. not QT or GTK)
  - - - - - -
Private hToolButton As ToolButton

Public Sub btnTest_Click()
   Dim intIndex As Integer
   For intIndex = 0 To 2
     hToolButton = New ToolButton(Me) As "My_Button"
     hToolButton.Top = 0 + (intIndex * 30)
     hToolButton.Left = 0
     hToolButton.Width = 300
     hToolButton.Height = 30
     hToolButton.Text = "MyButton" & CStr(intIndex)
   Next
End

Public Sub btnRemove_Click()

   Me["My_Button"].Delete

End

Public Sub My_Button_Click()

   Message.Info("Hello")

End
  - - - - - -

On LXDE the btnTest generates the 3 buttons
click btnRemove once removes the first drawn button the remaining 
buttons still function
click again and it removes the second drawn button the remaining button 
still functions
click again and it removes the third and last drawn button.

*** How could I just selectively remove a button based on index?

NB the index for 0 to 2 is just for this example test, in desired 
application there would be a variable and large number of buttons 
determined by data and user interaction.

As a workaround I could do
     hToolButton = New ToolButton(Me) As "My_Button" & CStr(intIndex)
which allows me to absolutely delete individual buttons but it means 
instead of having one
     Public Sub My_Button_Click()
I would have to code a large number sub just in case needed, for this 
example it would just need
     Public Sub My_Button0_Click()
     Public Sub My_Button1_Click()
     Public Sub My_Button2_Click()
But in the real application I may needs something like potentially 60 of 
them!

ALSO
running the same code in Debian10 KDE does not work the same.
Clicking btnRemove once removes the last drawn button only (and the 
first two buttons still work)
But when click btnRemove again to remove next button it complains 
Me["My_Button"] is a null object
K.


More information about the User mailing list