iOS Question #event support?

QtechLab

Active Member
Licensed User
Longtime User
In B4I you can't create a vb.net "With events" variable, some events are fired from their object, as Button_click.

If you want to create custom event of your classes you can use this code to implement them (i use this function every time i have to fire an event):

B4X:
Private Sub RaiseEvent(Caller as object, EventName as string, EventArgs as List)
  Dim SubEvent as string = "YourClassPrefix_" & EventName
  Try
      If SubExists(Caller, SubEvent, 1) then
          Callsub2(Caller, SubEvent, EventArgs)
      Else
          'Destination sub not found
      End if
  Catch
      'Other error
  End try
End Sub

The "Caller" is the module where you manage the event (the parent of your class)
 
Last edited:
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I like it, nice code but...

I am looking at the #event support that b4a and b4j classes have from an IDE standpoint.
In a class I create I can add at the top
#event NewData
#event Progress

Now when you use the b4a or b4j ide and you type sub [space] and [TAB], you get a list of class signatures with these events.

Reason I am asking is I have some non UI classes I want to share with the b4x community. :)
 
Upvote 0

QtechLab

Active Member
Licensed User
Longtime User
I like it, nice code but...

I am looking at the #event support that b4a and b4j classes have from an IDE standpoint.
In a class I create I can add at the top
#event NewData
#event Progress

Now when you use the b4a or b4j ide and you type sub [space] and [TAB], you get a list of class signatures with these events.

Reason I am asking is I have some non UI classes I want to share with the b4x community. :)

Oh... i didn't understand what you asked... sorry
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I think that it is better to use this code to raise an event:
B4X:
Private Sub RaiseEvent(Caller as object, EventName as string, EventArgs as List)
  Dim SubEvent as string = "YourClassPrefix_" & EventName
  Callsub2(Caller, SubEvent, EventArgs)
End Sub

There is no need to check whether the sub is implemented or not. Nothing will happen if it wasn't implemented.

#Event is supported. However for now it is only used with custom views and the designer.

The only difference between B4A/B4J here is that B4A/B4J support library compilation and the events metadata is added to the compiled library.
 
Upvote 0
Top