Global enumeration of named

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Global enumeration of named

Post by User_Russian »

This is necessary to generate unique numbers for objects such as windows, gadgets, files, images, etc.
This requires the reserved names for all objects, which to be global (for example: Window, Gadget, File, Timer etc).

Code: Select all

Enumeration Window
  #Window
EndEnumeration


DeclareModule x
Enumeration Window
  #Window
EndEnumeration
EndDeclareModule

Module x
  
EndModule

Debug #Window
Debug x::#Window ; Must be 1.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Global enumeration of named

Post by ts-soft »

+1

like this, fullqualified:

Code: Select all

 DeclareModule Common
  Enumeration Gadgets
    #btn_1
    #btn_2
  EndEnumeration
EndDeclareModule

Common::Enumeration Gadgets
  #btn3
EndEnumeration

Debug #btn3 ; should 2 
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
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Global enumeration of named

Post by User_Russian »

Code: Select all

DeclareModule Common
  Enumeration Gadgets
    #btn_1
    #btn_2
  EndEnumeration
EndDeclareModule

Enumeration Common::Gadgets
  #btn3
EndEnumeration

Debug #btn3 ; should 2
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Global enumeration of named

Post by ts-soft »

thx :D , works fine
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
User_Russian
Addict
Addict
Posts: 1520
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Global enumeration of named

Post by User_Russian »

But the drawback of this method is that you need to know the exact name of the module.

It is better if it had special names like PB_Enum_Window, PB_Enum_Gadget, etc, which were reserved names and would be's global throughout the code, including the modules.

Code: Select all

DeclareModule Common
  Enumeration PB_Enum_Gadget
    #btn_1
    #btn_2
  EndEnumeration
EndDeclareModule

Enumeration PB_Enum_Gadget
  #btn3
EndEnumeration

Debug #btn3 ; should 2
Post Reply