[wish] Library developers to be able to include pre defined events.

barx

Well-Known Member
Licensed User
Longtime User
I'm not too sure on the wording of this one, but you know when you go to write a sub and you can press tab to get a list of possible views. Then selecting one brings up a list of possible events for that view. Can we have the ability to include our own events (when creating a library) to this list.

I'm not too sure how this could be accomplished, whether it would be an xml based file, whether the doclet could be updated to manage this info somehow.

Just a thought (and wish) :)
 

Informatix

Expert
Licensed User
Longtime User
I'm not too sure on the wording of this one, but you know when you go to write a sub and you can press tab to get a list of possible views. Then selecting one brings up a list of possible events for that view. Can we have the ability to include our own events (when creating a library) to this list.

I'm not too sure how this could be accomplished, whether it would be an xml based file, whether the doclet could be updated to manage this info somehow.

Just a thought (and wish) :)

It's already possible. Example:
@Events(values = {"Done (ID As String)"})
 

barx

Well-Known Member
Licensed User
Longtime User
I really need to start requesting features that don't already exist lol.

So, to define events in a class module is it something like this?

B4X:
#Region Events
#Event: Click(Position as Int)
#Event: LongClick(Position as Int)
#Event: EndAnimation(Open as Boolean)
#End Region

Thanks
 

Sergio Haurat

Member
Licensed User
Longtime User
Someone can give a simple run an #Event: ?.
I need to declare (with or without parameters)
Somewhere in the code at run time call an RiseEvent
 

DonManfred

Expert
Licensed User
Longtime User
What exactly you want to do? Please describe it more in details.
 

Sergio Haurat

Member
Licensed User
Longtime User
My English may be difficult for you because I'm using Google translator, Let's talk in a language we both understand, Generic B4A code :)

Main Activity

B4X:
Sub Globals
  Private asd as MyClass
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.LoadLayout("actMain.bal")
  asd.Initialize(Me, "ClassEventTrap")
  asd.FireEvent(-1)
End Sub

' ***************** This never fires ******************
Sub DataColumn_IndexOutOfRange(Index As Long)
  Dim logError As String = "Out of range " & Index
  Log(logError)
End Sub

MyClass Class
B4X:
#Event: IndexOutOfRange(Index as Long)

Private Sub Class_Globals
    Private mTarget As Object
    Private mEventName As String
End Sub

Public Sub Initialize(Target As Object, EventName As String)
  mTarget = Target
  mEventName = EventName
End Sub

Public Sub FireEvent(Index as Long)
  If Index > 0 Then
    Log("Correct value > 0")
  Else
    CallSub2(mTarget, mEventName & "_IndexOutOfRange", Index)
  End If
End Sub

I understand that the #Event is for use with the combination of the word Sub and TAB key, I see that in its implementation at runtime not work, it is necessary to convert it to lib or something like that

Thanks for your help and patience
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime AsBoolean)
Activity.LoadLayout("actMain.bal")
asd.Initialize(Me, "ClassEventTrap") ' You set the Eventname to ClassEventTrap here
asd.FireEvent(-1)
End Sub
' An Event-sub must begin with that eventname you defined
Sub ClassEventTrap_IndexOutOfRange(Index AsLong)
  Dim logError AsString = "Out of range " & Index
  Log(logError)
End Sub

Why do you think

B4X:
DataColumn_IndexOutOfRange(Index As Long)

is the right name for that sub? You did not define DataColumn as eventname
 
Last edited:

Sergio Haurat

Member
Licensed User
Longtime User
It was a mistake to spend writing code project to example . The sub is correct in the project. classeventtrap is for example
 

DonManfred

Expert
Licensed User
Longtime User
Maybe you can do a check if the sub exists...
I´m not familar with creating classes. I just want to help

B4X:
Public Sub FireEvent(Index As Long)
  If Index > 0 Then
  Log("Correct value > 0")
  Else
     If SubExists(mTarget,mEventName & "_IndexOutOfRange") Then
     CallSub2(mTarget, mEventName & "_IndexOutOfRange", Index)
     Else
       Log("ERROR 404 - SubNotFound: "&mEventName & "_IndexOutOfRange") ' :-)
     End If
  End If
End Sub
 

Sergio Haurat

Member
Licensed User
Longtime User
I found the issue! When Erel told me to look at the calendar example, did not know that the call to sub, I do it from a class to an activity, this is solved using CallSubDelayed2 this can interact between classes and activities or other combinations.

Erel, you think that will be solved in the final version 3.5 the problem of combining the word Sub and TAB key when the class is not compiled

Thank you both for the help
 
Top