Named enumeration

Just starting out? Need help? Post your questions and find answers here.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Named enumeration

Post by Inner »

Hello all,
Could someone inform me on what the point of a 'Named enumeration' is exactly? the documentation is a little vague.
Axolotl
Enthusiast
Enthusiast
Posts: 449
Joined: Wed Dec 31, 2008 3:36 pm

Re: Named enumeration

Post by Axolotl »

Hi Inner,

you can create constants on different locations (mainfile, includefiles, ...) and you get always a unique constant, which is helpful with windows and gadgets
If you work with modules you have to place the enumerations in the declaremodule section to be unique. Inside a Module the naming does not work
In one sentence: Enumerations with the same name are continued:

Code: Select all

    Enumeration EGadget 
    #GadgetInfo ; will be 0
    #GadgetText ; will be 1
    #GadgetOK   ; will be 2
  EndEnumeration


Debug "#GadgetInfo = " + #GadgetInfo ; will be 0 

  Enumeration EGadget  ;' same name con
    #GadgetHelpInfo ; will be 3
    #GadgetHelpText ; will be 4
    #GadgetHelpOK   ; will be 5
  EndEnumeration

Debug "#GadgetHelpInfo = " + #GadgetHelpInfo ; will be 3
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Named enumeration

Post by TI-994A »

Inner wrote:...what the point of a 'Named enumeration' is exactly?

Code: Select all

Enumeration windows
  #window1   ;starts a new enumeration from 0
  #window2
  #window3
EndEnumeration

Enumeration gadgets
  #gadget1   ;starts a new enumeration from 0
  #gadget2
  #gadget3
EndEnumeration

Enumeration images
  #image1 = 3   ;starts this enumeration from 3
  #image2
  #image3  
EndEnumeration

Enumeration windows
  #window4   ;continues from the last "windows" number
EndEnumeration

Enumeration
  #gadget4   ;starts a new enumeration from 0
EndEnumeration

Enumeration images
  #image4   ;continues from the last "images" number
EndEnumeration

Debug #window1   ;0
Debug #window2   ;1
Debug #window3   ;2
Debug #window4   ;3
Debug #CR$
Debug #gadget1   ;0
Debug #gadget2   ;1
Debug #gadget3   ;2
Debug #gadget4   ;0
Debug #CR$
Debug #image1    ;3
Debug #image2    ;4
Debug #image3    ;5
Debug #image4    ;6
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: Named enumeration

Post by Inner »

Ahuh! thanks guys, appreciate the knowledge.
infratec
Always Here
Always Here
Posts: 6874
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Named enumeration

Post by infratec »

Long time I didn't know for what I should use this, but ...

If you have many pbi files which can be used in different projects and they include PostEvent()
with own events, then it make sense to use the name, so that every pbi extends the enumeration,
so you can still use the names of the constants without thinking about double numbers.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Named enumeration

Post by ts-soft »

Here a Example:

Code: Select all

DeclareModule CommonConstants
  ; Form
  Enumeration FormWindow
  EndEnumeration
  Enumeration FormGadget
  EndEnumeration
  Enumeration FormMenu
  EndEnumeration
  Enumeration FormImage
  EndEnumeration
  Enumeration FormFont
  EndEnumeration
  ; Event
  Enumeration EventCustom #PB_Event_FirstCustomValue
  EndEnumeration
  Enumeration EventTypeCustom #PB_EventType_FirstCustomValue
  EndEnumeration
EndDeclareModule

Module CommonConstants
EndModule

UseModule CommonConstants
Serves as a replacement for #PB_Any
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply