Page 1 of 1

shared for ModulDeclare

Posted: Fri Sep 04, 2015 7:09 pm
by GPI
I want to use mystuff.pbi in more than one project, but I want to control the code with some constant.
For Example:

Code: Select all

#MyStuff_ThreadSave=#true
xincludefile "mystuff.pbi"
mystuff.pbi

Code: Select all

CompilerIf Not Defined(MyStuff_ThreadSave,#PB_Constant)
  #MyStuff_ThreadSave=#false
CompilerEndIf

CompilerIf MyStuff_ThreadSave
  debug "something slow but save"
CompilerElse
  debug "something fast and dirty"
CompilerEndif
When I want to access a constant from outside a module, I can handle this with this, but only for one constant:

Code: Select all

#myconstant=1

DeclareModule test  
EndDeclareModule

CompilerIf #myconstant
  Module test
    #myconstant=#True
CompilerElse
  Module test
    #myconstant=#False
CompilerEndIf    
    Debug #myconstant  
EndModule
My suggestion, expand the share functionality to modules, for example.

Code: Select all

#myconstant=1

DeclareModule test
 Shared #myconstant  
EndDeclareModule

Module test
    Debug #myconstant
EndModule
I know, that I could use a Common-Modul, but than the definition of the constant can't be near the XIncludeFile.