Errors, bugs, questions - page 2347

 
Andrey Khatimlianskii:

But I didn't manage to implement it for different libraries either. To connect several libraries with such macros in one line and to call OnTick for all libraries.

I don't really understand even an example, what I want to get. Can you show me?


ZZZ As for the manager, see. EventBase.mqh here. Stupidly made everyone an heir and when a new object appeared, its pointer went to a common list, which was called by a for loop in each On-event.

 
fxsaber:

I can't even get an example of what I want to get. Can you show me?

MyClass_1.mqh:

class Myclass_1
  {
public:
   void              OnInit(){Print("Init 1");};
  };


MyClass_2.mqh:

class Myclass_2
  {
public:
   void              OnInit(){Print("Init 2");};
  };


Expert.mq5:

#include <MyClass_1.mqh>
#include <MyClass_2.mqh>

Myclass_1 m_class_1;
Myclass_2 m_class_2;

void OnInit( void )
{
  Print( "Init EA" );
}


To get all 3 printers as a result of execution: "Init 1", "Init 2" and "Init EA"

 

Hi all.

I callIndicatorParameters function from expert, but get error 4014. What is it may be - please advise? Build 1960.

 
Andrey Khatimlianskii:

To connect several libraries with such macros in one line, and to call OnTick to call all libraries OnTick.

Make a macro wrapper around the import which forms a class by name of the library (class##libname) and uses the context for the call inside the wrapper (libname::oninit)

and the class is dumped to the above manager.

but for each lib a separate line.

 
TheXpert:

Make a macro wrapper around the import that forms a class by the name of the library (class##libname)

This is a bit tricky for me, so I'll google it.

 
Kuzmich:

Hi all.

I callIndicatorParameters function from expert, but get error 4014. What is it may be - please advise? Build 1960.

If you have 3 inludniks, then my code should work, but for each class should prescribe macro substitutions, here is my example, it seems to work, but I will check yet:

class Myclass
  {
public:
                     Myclass(){};
                    ~Myclass(){};
   void              OnInit()  {Print(__FUNCSIG__," выполнен");};
   void              OnDeinit(int Reason){Print(__FUNCSIG__," выполнен");}
   void              OnTick()  {Print(__FUNCSIG__," выполнен");};
   void              OnTimer() {Print(__FUNCSIG__," выполнен");};
  } m_class;
//+------------------------------------------------------------------+
#define  MyClassOnInit m_class.OnInit();
void OnInit( void ){ MyClassOnInit; EventSetMillisecondTimer(300); ::MyClassOnInit_(); }
#define OnInit MyClassOnInit_
//+------------------------------------------------------------------+
#define  MyClassOnDeinit(Reason) m_class.OnDeinit(Reason);
void OnDeinit( const int Reason ){ MyClassOnDeinit(Reason); ::MyClassOnDeinit_(Reason); }
#define OnDeinit MyClassOnDeinit_
//+------------------------------------------------------------------+
#define  MyClassOnTimer m_class.OnTimer();
void OnTimer( void ){ MyClassOnTimer; ::MyClassOnTimer_(); }
#define OnTimer MyClassOnTimer_
//+------------------------------------------------------------------+
#define  MyClassOnTick m_class.OnTick();
void OnTick( void ){ MyClassOnTick; ::MyClassOnTick_(); }
#define OnTick MyClassOnTick_
//+------------------------------------------------------------------+

and in the Expert Advisor code I just include one #include <fileMyclass.mqh>

in your example, all three files must be closed (at the very bottom of the code) with my macro substitutions (and substitute the names m_class2 , m_class3...)

Andrey Khatimlianskii:

Already suggested solution for one-type class: inherit it from CObject, and add macro substitution to class manager which will store all added instances in CArrayObj, loop through it and call required OnXXX function.

I haven't managed to implement this for different libraries either. To connect several libraries with such macros in one line, and to call OnTick of all libraries.

example is needed, I don't know how and didn't work with "macro substitution in class manager"

 
Andrey Khatimlianskii:

To get all 3 printers: "Init 1", "Init 2" and "Init EA" as a result of execution

Do manager. The example of the source code above has shown. Macros are for other things, though.

 
Andrey Khatimlianskii:

It's a bit complicated for me, so I googled it.

It's not going to be pretty, but you can cut it down to something like this:

// for libsample
#import "libsample.ex5"
IMPORT_EA_INTERFACE // здесь список импортируемых функций. они по идее одинаковые, поэтому можно в отдельный дефайн
#import
 DECLARE_AND_REGISTER(libsample) // здесь генерация класса-обертки для libsample который обернет импортированные функции и зарегистрируется в менеджере
 

Here is a direct call and example of implementation without manager.

#define  IMPORT_EA_INTERFACE \
void f1(); \
void f2(); \

#define  DECLARE_AND_REGISTER(x) \
class ImportFrom_##x \
{ \
public: \
   static void f1() { x::f1();} \
   static void f2() { x::f2();} \
}; \

#import "libsample.ex5"
IMPORT_EA_INTERFACE
#import
 DECLARE_AND_REGISTER(libsample)

#import "libsamplesecond.ex5"
IMPORT_EA_INTERFACE
#import
 DECLARE_AND_REGISTER(libsamplesecond)

void OnStart()
{
   ImportFrom_libsample::f1();
   ImportFrom_libsample::f2();

   ImportFrom_libsamplesecond::f1();
   ImportFrom_libsamplesecond::f2();
}

If ImportFrom class has manager registration and non-static functions, everything can be called automatically for all imported either

 
TheXpert:

Here is a direct call and example of implementation without manager.

If ImportFrom class has manager registration and non-static functions, everything can be called automatically for all imported either

Got the idea, thanks.

Not 100% transparent, but better than it is at the moment.

Reason: