Page 1 of 1
Enumeration Multi constant definition in the same enum level
Posted: Mon Apr 22, 2019 9:57 am
by Kurzer
Hello Fred,
it would be great if you could add a feature to Enumeration to define several constants with the same value in the actual enumeration level. This could be look like this:
Code: Select all
Enumeration
#ImageGadget, #Window, #Image
#TextStatus
#TextViewer
EndEnumeration
In this case #ImageGadget, #Window and #Image would all be defined as 0. Then #TextStatus = 1, #TextViewer = 2
Kind regards
Kurzer
Re: Enumeration Multi constant definition in the same enum l
Posted: Mon Apr 22, 2019 4:10 pm
by davido
@
kurzer,
I don't know if you are aware that the manual states that it can be done thus:
Code: Select all
Enumeration
#ImageGadget
#Window = #ImageGadget
#Image = #ImageGadget
#TextStatus
#TextViewer
EndEnumeration
Debug #ImageGadget
Debug #Window
Debug #Image
Debug #TextStatus
Debug #TextViewer
Re: Enumeration Multi constant definition in the same enum l
Posted: Mon Apr 22, 2019 6:55 pm
by Kurzer
davido,
thanks for the tip.
I know this kind of definition, this is how I solve it at the moment.
Re: Enumeration Multi constant definition in the same enum l
Posted: Tue Apr 23, 2019 8:30 am
by Micoute
Code: Select all
Enumeration Windows
#Window
EndEnumeration
Enumeration Gadgets
#ImageGadget
#TextStatus
#TextViewer
EndEnumeration
Enumeration Images
#Image
EndEnumeration
Debug #ImageGadget
Debug #Window
Debug #Image
Debug #TextStatus
Debug #TextViewer
__________________________________________________
Code tags added
23.04.2019
RSBasic
Re: Enumeration Multi constant definition in the same enum l
Posted: Tue Apr 23, 2019 9:47 am
by Josh
kurzer wrote:
Code: Select all
Enumeration
#ImageGadget, #Window, #Image
#TextStatus
#TextViewer
EndEnumeration
Writing windows, gadgets, images etc. into one enumeration is complete nonsense. Like Micoute wrote, each of these 'groups' belongs its own named Enumeration, which can be continued in any IncludeFile at any time.
Code: Select all
Enumeration Windows
#MyWinA
#MyWinB
EndEnumeration
Enumeration Gadgets
#MyGadgetA
#MyGadgetB
#MyGadgetC
EndEnumeration
Enumeration Images
#MyImageA
#MyImageB
EndEnumeration
; In a other includefile
Enumeration Images
#MyImageC
EndEnumeration
Re: Enumeration Multi constant definition in the same enum l
Posted: Tue Apr 23, 2019 11:30 am
by Kurzer
Yes, I get the point.
My example was unfortunately not so well chosen.
The idea for this request just came to me when I wrote a small code that has only one window and one image, but several gadgets.
I could declare it that way:
Code: Select all
#Window = 0
#Image = 0
Enumeration
#Gadget1
#Gadget2
#Gadget3
;.. and so on
EndEnumeration
In this moemnt I found it "quite nice" if I could write it as shown in my first example.
But this request is not that important either. Possibly there would be use cases, where one can use this exactly in this form, but I'm afraid I can't think of one right now.

Re: Enumeration Multi constant definition in the same enum l
Posted: Tue Apr 23, 2019 3:59 pm
by Michael Vogel
Not sure if this will make you happy...
Code: Select all
Macro EnumAsAbove
= #PB_Compiler_EnumerationValue-1 :
EndMacro
Enumeration
#A
#B EnumAsAbove #C EnumAsAbove
#D
EndEnumeration
Debug #A
Debug #B
Debug #C
Debug #D
Re: Enumeration Multi constant definition in the same enum l
Posted: Tue Apr 23, 2019 5:20 pm
by Sicro
Code: Select all
Macro DefineConstants(_value_, _target1_, _target2_=PB_Ignore, _target3_=PB_Ignore, _target4_=PB_Ignore)
#_target1_ = _value_
CompilerIf Not Defined(_target2_, #PB_Constant) : #_target2_ = _value_ : CompilerEndIf
CompilerIf Not Defined(_target3_, #PB_Constant) : #_target3_ = _value_ : CompilerEndIf
CompilerIf Not Defined(_target4_, #PB_Constant) : #_target4_ = _value_ : CompilerEndIf
EndMacro
; Examples:
DefineConstants(10, a)
Debug #a
DefineConstants(10, b, c)
Debug #b
Debug #c