Jump to content

Event handling using tags


steved

Recommended Posts

I've added an option to widgets to assign a 'tag' value (as is done in Delphi) which can greatly simplify event handling - overall it may well save both RAM and code space in some applications - no need to do lots of comparisons with widget pointers.

For example, a keypad can assign tags which convert readily to ASCII characters, permitting use of generic decoding routines.

The notes in the attached files give an example.

Very simple addition.

event_handling_using_tags.zip

Link to comment
Share on other sites

  • 2 weeks later...

Getting round this behaviour is difficult and relies on "error" values. It is easier to assume that 0 is that error value. It correspond nicely to an default initialised init structure. As the user sets tag values there is no reason that zero is any worse an error value than any other and there are a number of implemtation reasons why it makes a good one in this situation.

Link to comment
Share on other sites

Probably we could just typedef the widget tag type so it is a signed value and we can use -1 for an invalid widget (so the user can check for < 0) and use the positive values including zero as the real tag values?

Otherwise I'll just note that down in the documentation very very carefully.

~ Tectu

Link to comment
Share on other sites

I took a look and I see one potential problem: The gwinGetTag() routine returns the tag of the widget or 0 if it is not a widget. However, it is completely valid to set the tag of a widget to 0. I think that this behavior should be changed.

~ Tectu

I took the view that we don't care where the tag comes from; our only concern is that if it's non-zero we process it, and carry out some action determined by the tag's value. So zero for 'do nothing' is convenient.

Link to comment
Share on other sites

If using consecutive tag values starting from 1, 0 as the do nothing case works well as the compiler should generate a switch jump table where 0 is the first element of that table thus leading to the most efficient code (no table offsets to add by the compiler).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...