Hello Devs
I have this code in Clarion 10 that creates buttons at run time, is it possible to assign events to them?
Where when clicking calls a function?
Variables/fields of the reference-to-function type are available… So, a function/method to invoke on pressing the button can be associated with that button’s FEQ.
Reference variables of procedural types were introduced in C11.
Declare an event handler function type:
EventHandler PROCEDURE(SIGNED ev),BYTE,TYPE
or, if it’s desirable to have such handler as a method of some class:
EventHandler PROCEDURE(*SomeClass, SIGNED ev),BYTE,TYPE
If a QUEUE is using for mapping:
FeqQueue QUEUE
feq SIGNED
handler &EventHandler
END
...
FeqQueue,feq = <control FEQ>
FeqQueue.handler &= <handler function for this control>
ADD (FeqQueue, +FeqQueue.feq)
...
ACCEPT
FeqQueue.feq = FIELD()
GET (FeqQueue, +FeqQueue.feq)
IF ERRORCODE() = 0
CASE FeqQueue.handler (EVENT())
OF LevelBenign
OF LevelFatal
BREAK
OF LevelNotify
CYCLE
END
ELSE
<other processing>
END
END
If TIE function is using for mapping:
EventHandlerAS ASTRING('EventHandler')
handler &EventHandler,AUTO
...
TIE (EventHandlerAS, feq, ADDRESS (<event handler function for this control>)
...
ACCEPT
handler &= TIED (EventHandlerAS, FIELD())
IF NOT hander &= NULL
CASE handler (EVENT())
OF LevelBenign
OF LevelFatal
BREAK
OF LevelNotify
CYCLE
END
ELSE
<other processing>
END
END
If user-defined property is using for mapping:
EventHandlerProp STRING('EventHandler')
handler &EventHandler,AUTO
...
feq {EventHandlerProp} = ADDRESS (<event handler function for this control>)
...
ACCEPT
handler &= 0 + FIELD(){EventHandlerProp}
IF NOT hander &= NULL
CASE handler (EVENT())
OF LevelBenign
OF LevelFatal
BREAK
OF LevelNotify
CYCLE
END
ELSE
<other processing>
END
END
Off-topic. If someone is missing possibility to associate some values with QUEUEs or not likes the NAME attribute for association, look at TIE/TIED and INSTANCE.