get event type?

Byak@

Active Member
Licensed User
B4X:
sub appstart
addevent("button1","Click","ev")
addevent("form1","MouseUp","ev")
addevent("timer1","Tick","ev")
end sub

sub  ev

end sub

when "ev" called i may get name of control with keyword SENDER but how can i get what EVENT called this sub?
 

Mr_Gee

Active Member
Licensed User
Longtime User
untill it someone has a better solution would this help?
B4X:
sub appstart
addevent("button1",Click,"ev1")
addevent("form1",MouseUp,"ev2")
addevent("timer1",Tick  ,"ev3")
end sub

sub  ev1
    ev("Button")    
end sub
sub  ev2
    ev("MouseUp")
end sub
sub  ev3
    ev("Tick")
end sub

sub  ev(showtype)
    MsgBox("Type " & showtype)
end sub
 

Byak@

Active Member
Licensed User
no,you dont understand me=)
for example i have 100 controls...and i must add 100 subs?

but this problem i have?when i create plugins for my program with Scripting dll
plugins can arr objects to program but now i want add events for this objects,and code of this events in plugin.

my first example shows exactly the problem
 

agraham

Expert
Licensed User
Longtime User
for example i have 100 controls...and i must add 100 subs?
No. Just have one event Sub for each type of event then you know the Event type and can use Sender for the source of the event.

B4X:
sub appstart
  addevent("button1","Click","clickev")
  addevent("form1","MouseUp","mupev")
  addevent("timer1","Tick","tickev")
end sub

sub  clickev
  ...
end sub

sub  mupev
  ...
end sub

sub  tickev
  ...
end sub
 

Byak@

Active Member
Licensed User
i think about it,but in program used all(maybe not all but many) controls and objects from any dlls and i must create very many subs includes all events...
it is not good too...
and most importantly it is unnecessary, it may be sufficient to know what event

maybe it's real with door dll and object "event"?
 

agraham

Expert
Licensed User
Longtime User
maybe it's real with door dll and object "event"?
No, it is not possible. It would need a modification to Basic4ppc to save the event name as well as the sender name. Presently the event name is lost once the event sub has been identified by the Basic4ppc event code.

Surely there are not that many events you need, and surely it is better to have small individual event Subs handling each type of event rather than one huge Sub with lots of conditional tests inside it trying to handle all the possible event types!

EDIT:- Remember that you don't need a different event sub for each control or object, only different ones for each individual event name. You can hide them in a module!
 
Last edited:

Byak@

Active Member
Licensed User
thanks you agraham. it is not good but it better then nothing
 

Byak@

Active Member
Licensed User
thanks erel, but it was example and in my app some events not been used(mouseup,mousedown,mousemove,keypress).
but what you say about add new keyword in basic in latest version? =)
 
Top