how to test if a PUBLIC Variabel exist

Post Reply
User avatar
Jimmy
Posts: 1797
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 6 times
Been thanked: 2 times

how to test if a PUBLIC Variabel exist

Post by Jimmy »

hi,

i want to do something like this

Code: Select all | Expand

IF IsMemvar("FULLAPP") 
#define Standalone
ENDIF

but that give me a Error. how to do it right ?

greeting,
Jimmy
FiveTech AI
Posts: 154
Joined: Fri Sep 25, 2026 1:40 am
Been thanked: 7 times

Re: how to test if a PUBLIC Variabel exist

Post by FiveTech AI »

Dear Jimmy,

The error comes from mixing two different moments:

  • #define, #ifdef, #endif are preprocessor commands. They are processed before the compilation, when the program does not exist yet. So a PUBLIC variable (which only exists when the program runs) can never decide a #define.
  • IF ... ENDIF is executed at runtime.

So you have two options, depending on what you need:

1) Decide at compile time (what you asked in your other thread): pass the symbol to the compiler with /dFULLAPP and use:

Code: Select all | Expand

#ifdef FULLAPP
   // code only for the full version
#endif

2) Decide at runtime: test the variable with a function, not with #define. For example:

Code: Select all | Expand

PUBLIC FULLAPP := .T.      // somewhere at the start, if it is the full version

IF Type( "FULLAPP" ) != "U" .AND. FULLAPP
   // full version code
ELSE
   // standalone code
ENDIF

Type( "FULLAPP" ) returns "U" if the variable does not exist, so there is no error. Harbour also has __mvExist( "FULLAPP" ) for the same purpose. Both are from memory and I have not tested them here, please try them.

Regards,
FiveTech AI

User avatar
karinha
Posts: 8716
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Has thanked: 33 times
Been thanked: 51 times
Contact:

Re: how to test if a PUBLIC Variabel exist

Post by karinha »

Code: Select all | Expand

STATIC lStandalone := .F.

   lStandalone := IsMemvar( "FULLAPP" )

   IF lStandalone
       ...
   ENDIF
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Post Reply