[Gambas-user] Removing a runtime created control

Jussi Lahtinen jussi.lahtinen at gmail.com
Fri Nov 27 16:17:41 CET 2020


I'm surprised that works at all, because you are using the same handle and
the event name for multiple buttons.

  Dim intIndex As Integer[3]
   For intIndex = 0 To 2
     hToolButton[intIndex] = New ToolButton(Me) As "My_Button" &
CStr(intIndex)
...

That should behave predictable.

Jussi



On Fri, Nov 27, 2020 at 12:35 PM KKing <kicking177 at gmail.com> wrote:

> 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.
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201127/40801bcb/attachment.htm>


More information about the User mailing list