Suppose you have a popup menu (or similar) with a bunch of entries that you want to ensure are ticked/unticked correctly based on the values of particular variables. One way of doing this would be:
Code: Select all
If var.l=#this
SetMenuItemState(#menu, #menuitem, #True)
Else
SetMenuItemState(#menu, #menuitem, #False)
EndIf
But, it occurs to me that "if var.l=#this" is a true/false matter in the first place, so in theory something along the lines of this should work, and is much shorter:
Code: Select all
SetMenuItemState(#menu, #menuitem, var.l=#this)
Except of course it doesn't, because it assigns var.l the value of #this, rather than testing for equality (and seems to return #true in the process). A hacky solution is to move the test into a procedure:
Code: Select all
Procedure.l Compare(in.l, comp.l)
Define out.l
If in=comp
out=#True
Else
out=#False
EndIf
ProcedureReturn out
EndProcedure
SetMenuItemState(#menu, #menuitem, Compare(var.l, #this))
This is better, and if there are a bunch of menu entries to be dealt with, it makes the code for doing so a lot shorter and more readable (one line per menu entry, which will tick or untick the menu entry as required). The question is, whether there is a native way of testing for equality within the parameters to a procedure. Compare() feels pointless, even though I can't find a way to do without it.
Any suggestions?