View previous topic :: View next topic |
Author |
Message |
wsmith9920
Joined: 16 Sep 2013 Posts: 19
|
Posted: Fri Nov 01, 2019 2:04 pm Post subject: Callback functions with arguments? |
|
|
Is it possible to supply an argument with a clearwin callback function? I have been using a menu and window built with %mn. The attempt to supply a callback function with an argument will compile and link fine, but it generates run-time errors. I can work around this problem (set up multiple dummy callback functions which then call the actual one with the desired argument) but it seems silly to do it this way. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Fri Nov 01, 2019 2:28 pm Post subject: |
|
|
ClearWin+ callback functions have no arguments.
You can have one callback for a number of menu items and then use clearwin_string@("CURRENT_MENU_ITEM") to identify the item that has been selected.
Another option is use the standard callbacks 'SET and/or '+' when defining the menu items.
Last edited by PaulLaidler on Fri Nov 01, 2019 5:57 pm; edited 1 time in total |
|
Back to top |
|
|
wsmith9920
Joined: 16 Sep 2013 Posts: 19
|
Posted: Fri Nov 01, 2019 2:40 pm Post subject: |
|
|
Thanks Paul. Your first suggestion sounds attractive. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sun Nov 03, 2019 3:42 pm Post subject: |
|
|
It's an interesting point as to whether one addresses the callback problem with many, individually-named, but simple(r) functions, or fewer multifunctional callback routines. I suppose the final choice must reflect the programmer's preference, or 'style'.
My own style is for the many routines, but this did not reflect a conscious choice, but rather that my reading of the documentation some decades ago did not allow for any other approach. I was rather appalled at how many routines it took to service menu bars and toolbars, and the multifunction callback idea therefore had an appeal. However, browsing through my source code files, I can at least tell the purpose of each of the individual callback functions through judicious choice of routine name, and I do know that altering such a function does not have much potential for side effects.
Eddie |
|
Back to top |
|
|
wsmith9920
Joined: 16 Sep 2013 Posts: 19
|
Posted: Sun Nov 03, 2019 4:34 pm Post subject: |
|
|
I ultimately used Paul's suggestion to use clearwin_string@, but there are times when a less elegant method will be easier to understand in a couple of weeks when I have forgotten what I have written |
|
Back to top |
|
|
|