Forum > General

Define a global symbol name

(1/1)

simone:
As far as I know, using {$DEFINE} it is possible to define a symbol name whose scope is the current module (i.e. unit or program). I want to define a global symbol, i.e. a symbol visibile in all the units of a project. Now I exploit the following workaround: I use {$include} to include a .inc file with needed definitions in all the units. Is there a smarter way to do this (by code)?

dsiders:

--- Quote from: simone on January 13, 2019, 11:38:59 pm ---As far as I know, using {$DEFINE} it is possible to define a symbol name whose scope is the current module (i.e. unit or program). I want to define a global symbol, i.e. a symbol visibile in all the units of a project. Now I exploit the following workaround: I use {$include} to include a .inc file with needed definitions in all the units. Is there a smarter to do this (by code)?

--- End quote ---

You can add {$DEFINE}s using the Project or Package settings in the IDE. Compiler Options > Custom Options.

lucamar:
In code no, there's no way; just workarounds as you're using now--which is a rather extensively used workaround, BTW

You can add a global define in Lazarus IDE, as dsiders said, or add it as an argument to the compiler call:
    fpc -dMYDEFINE

Kays:

--- Quote from: lucamar on January 14, 2019, 12:03:10 am ---In code no, there's no way; just workarounds as you're using now […]

--- End quote ---
Seconded.


--- Quote from: lucamar on January 14, 2019, 12:03:10 am ---[…]     fpc -dMYDEFINE

--- End quote ---
Or write an appropriate fpc.cfg(5) in your project's base directory (assuming you're compiling everything from there). This will eliminate to write {$include myGlobalDefines.inc} in every source file.

jamie:
I usually have a COMMON unit where all other units include it in the USES list. It houses constants to be
used through out the app along with some on my own special moon lighting code that is shared among the
program..

UNIT GLOBE

Constant
    AGLOBEVALUE = ????????
 
   Add a lot of other stuff too while you are at it!

Navigation

[0] Message Index

Go to full version