[Gambas-user] Removing a runtime created control
Jussi Lahtinen
jussi.lahtinen at gmail.com
Fri Nov 27 19:41:39 CET 2020
I mean Last works inside the event handler, whatever had raised it.
Jussi
On Fri, Nov 27, 2020 at 8:39 PM Jussi Lahtinen <jussi.lahtinen at gmail.com>
wrote:
> At least here you seem to give a new handle: mTxt[fldNr] = New
> TextBox(Maske) As "MaskeFeld"
> The events are raised by the name: My_Button1_Change, My_Button2_Change,
> etc.
> If they are grouped you can just use Last (no dot) keyword.
>
> Jussi
>
>
> On Fri, Nov 27, 2020 at 5:35 PM Rolf-Werner Eilert <rwe-sse at osnanet.de>
> wrote:
>
>> Interesting, Jussi!
>>
>> My version also uses the same handle and event name for each object, and
>> it finds its events with the .Last property. This was described in some
>> help text. Maybe it's obsolete meanwhile? I always wondered how it could
>> work, but I just accepted it as given.
>>
>> Your version "New ToolButton(Me) As "My_Button" & CStr(intIndex)" is
>> much clearer to me, but how would I use .Last in this case? Or: how can
>> I find just "the object which has produced the Change event (for example)?
>>
>> Rolf
>>
>>
>> Am 27.11.20 um 16:17 schrieb Jussi Lahtinen:
>> > 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
>> > <mailto: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 ]----
>> >
>> >
>> >
>> > ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>> >
>>
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201127/dfdaf45d/attachment.htm>
More information about the User
mailing list