AddEvent Sender etc ?

Erel

B4X founder
Staff member
Licensed User
Longtime User
Sender is included. As an example you can see the CurrencyConverter example.

AddEvent and Control are not really required in Basic4android.
In Basic4ppc AddEvent was used to set the event sub to a sub other than the default sub which is derived from the control name.

In Basic4android you can set the event name during initialization and achieve the same result.
About Control keyword. In Basic4ppc each control had a unique and permanent name. The name concept is much weaker in Basic4android.
The reason is that objects are now "first class citizens". Check this code for example:
B4X:
Sub ButtonCreator (Text As String) As Button
 Dim b as Button
 b.Initialize("")
 b.Text = Text
 Return b
End Sub

...
For i = 1 to 10
 Activity.AddView(ButtonCreator("text" & i), 10, 10, 20, 20)
Next

'Or
Dim button as Button
button = ButtonCreator("sefew")
'now work with this button

You can even add your buttons to a List or Map (Hashtable) and then do something like:
B4X:
For i = 0 to List.Size - 1
 Dim b as Button
 b = List.Get(i)
 b.Color = Colors.Red
Next
 

agraham

Expert
Licensed User
Longtime User
Eventname in the Designer, or for a view added programmatically Initialize in Activity_Create, will vector the event.

Sender exists.

View is sort of like Control
B4X:
Sub Button2_Click
   Dim v As View
   v = Sender
   ToastMessageShow(v.Top, True)
End Sub
Next thing you'll be wanting to know the name of the control that is the Sender :) (that's another in-joke/sly dig!)
 

agraham

Expert
Licensed User
Longtime User
As the name parameter is not (yet ?) available I use the Tag parameter to know the Sender View.
Bet won I believe Erel! :)

Thanks Klaus. Erel and I had an interchange about this. I suggested setting Tag by default in the Designer to the control name but Erel wasn't keen so I bet him that someone would ask for a way to get the control name. You did!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
My first design did include a name property for objects.
However I then realized that it in many cases the name has no meaning (or doesn't exist).
The code in post #2 demonstrates it.

Using the Tag property to pass more information is much better than using the name property to pass information (and much more powerful). There are also technical reasons which make it pretty difficult to add a name property.
 

klaus

Expert
Licensed User
Longtime User
I was looking for the Name parameter to find what View has raised a common event.
For me the Tag parameter is OK, with it I can determine what View raised the. The Tag parameter has the advantage that we can set it to the value we want and no need to retrieve the name to get the wanted value (example for buttons in a keyboard).

Best regards.
 
Top