Recent

Author Topic: Define a global symbol name  (Read 2610 times)

simone

  • Hero Member
  • *****
  • Posts: 573
Define a global symbol name
« 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 way to do this (by code)?
« Last Edit: January 14, 2019, 01:52:05 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

dsiders

  • Hero Member
  • *****
  • Posts: 1080
Re: Define a global symbol name
« Reply #1 on: January 13, 2019, 11:58:20 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)?

You can add {$DEFINE}s using the Project or Package settings in the IDE. Compiler Options > Custom Options.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Define a global symbol name
« Reply #2 on: January 14, 2019, 12:03:10 am »
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
« Last Edit: January 14, 2019, 12:04:48 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Kays

  • Hero Member
  • *****
  • Posts: 575
  • Whasup!?
    • KaiBurghardt.de
Re: Define a global symbol name
« Reply #3 on: January 14, 2019, 01:36:59 am »
In code no, there's no way; just workarounds as you're using now […]
Seconded.

[…]     fpc -dMYDEFINE
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.
Yours Sincerely
Kai Burghardt

jamie

  • Hero Member
  • *****
  • Posts: 6133
Re: Define a global symbol name
« Reply #4 on: January 14, 2019, 02:30:19 am »
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!
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018