Wish "AS" keyword

Toky Olivier

Active Member
Licensed User
Longtime User
I think it would be easier if we can do like this (as in Pascal language) with "AS" keyword (for eg. in a Click event of a button):
B4X:
Dim strTag As String = (Sender As Button).Tag

If I'm not wrong, now I should do like this:
B4X:
Dim btn As Button = Sender
Dim strTag As String = btn.Tag
 

Emme Developer

Well-Known Member
Licensed User
Longtime User
If i remember correctly, you can make your casting function

B4X:
Sub Button(view As Object) As Button
    Return view
End Sub

dim strTag = Button(sender).tag
 

Toky Olivier

Active Member
Licensed User
Longtime User
I will check, but even if we can do like that, you need to do for all views + customviews that can send events: Label, Edit, ..., CustomListView, etc. Also, if you put the function in a code module or library, it becomes longer: MySharedModule.Label(sender).Tag for eg.
For me it's better if the solution is available within the language as it is already used for example in the forms:
- Array As Object(...)
- For Each v As B4XView In...
 
Top