Problem with ambit of variables between includes

 

Hi,
when I declare a variable in a included file, if this var is called of a included file loaded from it, the compiling fails, examples...

THIS WORKS FINE
Script...

#include <include1.mqh> // note: without this comment between include commands, the SRC style shows all in the same color
#include <include2.mqh>
int start(){Check();}

file include1.mqh...

#property library
bool CHECKSW=true;

file include2.mqh...

#property library
void Check(){if(CHECKSW) MessageBox("OK"); else MessageBox("KO");} 

THIS FAILS, error... 'CHECKSW' - variable not defined
Script...
#include <include1.mqh>
int start(){Check();}

file include1.mqh...

#include <include2.mqh>
#property library
bool CHECKSW=true;

file include2.mqh...

#property library
void Check(){if(CHECKSW) MessageBox("OK"); else MessageBox("KO");}


Anyone can help me?

Thanks

 
yotrader:

Hi,
when I declare a variable in a included file, if this var is called of a included file loaded from it, the compiling fails, examples...

THIS WORKS FINE
Script...

<CODE REMOVED>

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.


Maybe this will help: https://www.mql5.com/en/forum/116773
 
Those are include files, not libraries. Remove the #property
 
RaptorUK:

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.


Maybe this will help: https://www.mql5.com/en/forum/116773

Hi,

the post is edited I hope it's right now

thanks for all,

 
WHRoeder:
Those are include files, not libraries. Remove the #property

Hi,

Sorry, I have shown only fracments of the code for the example, (the #property library compiling command is necesary to use in the code of my include files and the use of this command I think is not limited to mq4 type files) and it is not have relevance in this problem.

Thank you

 

I want to simplify the explanation of my problem...

Main script...

#include <include1.mqh>
int start(){
  Myfunc();
}

include1.mqh ...

#include <include2.mqh>
bool CHECK=true;

include2.mqh ...

int Myfunc(){
  Print(CHECK);
}

Compiler error...

'CHECK' - variable not defined

ideas?

 

Hi,

I have encountered the solution !!! :)

Replacing the code of the include1.mqh with...

bool CHECK=true;
#include <include2.mqh>

Finally, the phrase "The #include command line can be placed anywhere in the program" can be wrong in the documentation https://docs.mql4.com/basis/preprosessor/include

the compiler seems that not works very fine ;)

Thanks at all

 
yotrader:

Hi,

I have encountered the solution !!! :)

Replacing the code of the include1.mqh with...

Finally, the phrase "The #include command line can be placed anywhere in the program" can be wrong in the documentation https://docs.mql4.com/basis/preprosessor/include

the compiler seems that not works very fine ;)

Thanks at all


The #include may be place anywhere in the code. Nevertheless anywhere does not mean randomly.
 
yotrader:

Hi,

I have encountered the solution !!! :)

Replacing the code of the include1.mqh with...

Finally, the phrase "The #include command line can be placed anywhere in the program" can be wrong in the documentation https://docs.mql4.com/basis/preprosessor/include

the compiler seems that not works very fine ;)

Thanks at all

In this particular case the compiler works very fine, you can't use a variable before you declare it.

#include is a directive for the preprocessor, not the compiler.

Reason: