FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour how to test if a PUBLIC Variabel exist
Posts: 1797
Joined: Thu Sep 05, 2019 05:32 AM

how to test if a PUBLIC Variabel exist

Posted: Sun Oct 11, 2026 03:42 PM

hi,

i want to do something like this

IF IsMemvar("FULLAPP") 
#define Standalone
ENDIF

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

greeting,

Jimmy
Posts: 150
Joined: Fri Sep 25, 2026 01:40 AM

Re: how to test if a PUBLIC Variabel exist

Posted: Sun Oct 11, 2026 03:51 PM

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:

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

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

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

Posts: 8716
Joined: Tue Dec 20, 2005 07:36 PM

Re: how to test if a PUBLIC Variabel exist

Posted: Sun Oct 11, 2026 05:00 PM
STATIC lStandalone := .F.

   lStandalone := IsMemvar( "FULLAPP" )

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

Continue the discussion