Page 1 of 1

Solved! Is it possible to change the value of a constant during compile time?

Posted: Mon Jul 29, 2024 9:13 pm
by SMaag
For controlling the compile process by code I'm searching for a Methode to change the value of constants!
I'm able to create the constant once. But I can't change the value!
Do anyone of you know a trick how to change the value of a constant.

Code: Select all

Macro macHashTag
  #  
EndMacro


Macro SetConstant(ConstantName, Value)
  CompilerIf Defined(ConstantName, #PB_Constant)
    ; redefine constant with new value???
     
  CompilerElse  ; Constant not defined   
    macHashTag#ConstantName = Value     
  CompilerEndIf 
EndMacro
  
SetConstant(MyConstant, 2)
SetConstant(MyConstant, 3)

Debug #MyConstant
What I want to do with it is:
Switching On/Off a Macro what does a PointerException Check!

if have such Macros what are controlling the PointerExceptionCheck
It can be switched On/Off by PbFwCfg_Module_CheckPointerException or global Off by PbFwCfg_Global_CheckPointerException

The PbFwCfg_Module_CheckPointerException I have to change between #False and #True some times during the compile time.

Code: Select all

 Macro mac_CheckPointer2(ptr1, ptr2, ProcRet=0)
    CompilerIf #PbFwCfg_Module_CheckPointerException And PbFw::#PbFwCfg_Global_CheckPointerException
      If (Not ptr1) Or (Not ptr2)
        DBG::Exception(#PB_Compiler_Module, #PB_Compiler_Procedure, DBG::#PbFw_DBG_Err_PointerIsNull) 
        ProcedureReturn ProcRet
      EndIf 
    CompilerEndIf
  EndMacro

Re: Is it possible to change the value of a constant during compile time?

Posted: Tue Jul 30, 2024 12:12 am
by idle
you can undefine the macro and make it empty then redefine it but it's compile time only

Code: Select all

Macro foo(x) 
    Debug "on" + Str(x)  
 EndMacro  
 
foo(123) 

UndefineMacro Foo 
Macro foo(x) 
EndMacro 

foo(234) 

UndefineMacro Foo 
 Macro foo(x) 
   Debug "on" + Str(x)  
EndMacro  

foo(345)


Re: Is it possible to change the value of a constant during compile time?

Posted: Tue Jul 30, 2024 8:29 am
by BarryG
SMaag wrote: Mon Jul 29, 2024 9:13 pmI'm able to create the constant once. But I can't change the value!
That's the idea. "Constant" literally means never-changing, so you can't change it. You want a variable, which can be changed.

Re: Is it possible to change the value of a constant during compile time?

Posted: Tue Jul 30, 2024 8:42 am
by Kiffi
BarryG wrote: Tue Jul 30, 2024 8:29 amThat's the idea. "Constant" literally means never-changing, so you can't change it. You want a variable, which can be changed.
+1

Solved!

Posted: Tue Jul 30, 2024 8:57 am
by SMaag
I think I solved it!

1. A part of my idea was totaly nonsens, because if the Procedure is compiled, it i not possible to change.
With that 80% of the Constant problem disappeared!

2. For 20% rest, I define a local constant in the Module what has the same name in all Modules.