Bug in MetaTrader MQ4.

 
Hey you all,

5 files.
Put them in the experts directory
Compile A.mq4
Compile B.mq4
Compile EA.mq4

Put EA.mq4 on a chart
Watch the "Experts" Tab
Search these 2 lines in the "Experts" tab:
ScenarioA: 1
ScenarioB: 0 !!!!!!

Error in scenario B:
Lib B has a variable named b
When the EA Calls Lib B function SetB, and then get it back by calling Lib B function GetB
we receive the right value.

But when the EA Calls Lib A function SetBFromA , and then try to get it back by calling Lib B function GetB we receive the wrong value.

This is because b seems to "live" in two separated memory blocks: if we will print GetB inside SetBFromA we will probably get the value of 1.

Are you aware of this bug?
Thanks
Ruby

B.mqh
#import "B.ex4"
void SetB(int value);
int GetB();



B.mq4

#property library

int b;

void SetB(int value)
{
   b = value;
}

int GetB()
{
   return (b);
}



A.mqh

#import "A.ex4"
void SetBFromA(int value);



A.mq4

#property library

#include "B.mqh"

void SetBFromA(int value)
{
   SetB(value);
}



EA.mq4

#include "A.mqh"
#include "B.mqh"

int init()
{
   ScenarioA();
   ScenarioB();
}

void ScenarioA()
{
   //Reset B directly
   SetB(0);
   
   //Set B directly
   SetB(1);
   
   Print("ScenarioA: ", GetB());
}

void ScenarioB()
{
   //Reset B directly
   SetB(0);

   //Set B from A 
   SetBFromA(1);
   
   Print("ScenarioB: ", GetB());
}

int start(){}
int deinit(){}
 
there are 2 copies of the B libraries: from EA and from A
You can check it with GetBFromA (like SetBFromA)
As designed. We'll think
 
Dear Slawa,

there are 2 copies of the B libraries: from EA and from A
You can check it with GetBFromA (like SetBFromA)
As designed


Right, that was the result of my observations and tests.

We'll think


The current implementation prevents from writing real libraries, because I must call the libraries from the main EA, and can't use calls from one library to another (in the same context of the main EA of course).

Imagine a set of libraries that MetaTrader users will write and publish. We will get a huge library data base
that will cause more and more investors move to MetaTrader, This is MetaTrader main interest.

For me, as a programmer, it is a design issue, it will help to write more and more libraries with very specific responsibilities(e.g. money managemnet strategies library, trailing stops strategies library etc.), to separate code to different modules, so EAs will become more readable and more easy to modify and enhance.


I really hope you can change the implementation real soon. I'm working on a trading Framework based on MQ4 and it will be much more effective if all modules will run in the same memory block (one instance in memory) like it is in every programming language.

One more thing: If you can publish object oriented language MQ++ language that would be great :)
Thanks a lot,
Keep on doing great job,
Ruby
Reason: