forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Callback functions with arguments?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
wsmith9920



Joined: 16 Sep 2013
Posts: 19

PostPosted: Fri Nov 01, 2019 2:04 pm    Post subject: Callback functions with arguments? Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Nov 01, 2019 2:28 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
wsmith9920



Joined: 16 Sep 2013
Posts: 19

PostPosted: Fri Nov 01, 2019 2:40 pm    Post subject: Reply with quote

Thanks Paul. Your first suggestion sounds attractive.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sun Nov 03, 2019 3:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
wsmith9920



Joined: 16 Sep 2013
Posts: 19

PostPosted: Sun Nov 03, 2019 4:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group