t.tutiya
(t.tutiya)
1
I want to create a function that creates a button_device, sets up a handler function, and returns that object.
However, the following function gives me a compile error.
CreateLoudButton(Name:string, Handler: widget_message->void):button_loud =
Button:button_loud = button_loud:
DefaultText := StringToMessage(Name)
Button.OnClick().Subscribe(Handler)
return Button
What am I doing wrong?
Thank you.
This should work :
my_custom_handler := class:
Callback: type{_(:widget_message) : void}
HandleOnClickEvent(Payload:widget_message):void=
Callback(Payload)
your_ui_class := class():
CreateLoudButton(Name:string, Handler: widget_message->void):button_loud =
Button:button_loud = button_loud:
DefaultText := StringToMessage(Name)
CustomHandler := my_custom_handler{Callback := Handler}
Button.OnClick().Subscribe(CustomHandler.HandleOnClickEvent)
return Button
I use this kind of setup literally in all my files, don’t know if it’s the right way to go, but it should work!
2 Likes
t.tutiya
(t.tutiya)
3
Your code worked perfectly!! Thank you!!!
1 Like
system
(system)
Closed
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.