Has anyone come across a multi-timer solution so that I don't have to reinvent the wheel myself? I don't see the implementation as being complicated by using pointers to the function. It is unlikely that it would not have already been implemented before me. That is, the original task is to create a timer with any periodicity and assign to it a function to handle the timer event. And there can be any number of timers.
Like this:
#include <Timer.mqh>
CTimer timers;
int x1=0;
int x2=0;
intOnInit()
{
timers.NewTimer(500, Sum1); // создаем новый таймер с периодом обновления 500 милисекунд и функцией-обраточником Sum1()
timers.NewTimer(2000, Sum2); // создаем новый таймер с периодом обновления 2000 милисекунд и функцией-обраточником Sum2()return(INIT_SUCCEEDED);
}
...
voidOnTimer()
{
timers.OnTimer();
}
//+------------------------------------------------------------------+void Sum1() { // данная функция вызывает с периодичностью 500 милисекунд
x1++;
if (x1==10) timers.KillTimer(Sum1); // удаляем этот таймер
}
void Sum2() { // данная функция вызывает с периодичностью 2000 милисекунд
x2++;
if (x2==10) timers.KillTimer(Sum2); // удаляем этот таймер
}
I.e. the initial task is to create a timer with any periodicity and map its timer event handling function to it. And there can be any number of timers.
1. Включите в свою программу класс CTimer 2. Создайте один объект класса СTimer. Например timers. 3. Создайте функции-обработчики необходимых таймеров формата void AnyNameFunction() {....} например с такими именами: 4. Когда вам необходимо создать и запустить таймер, сделайте так из любого места: 5. Когда вам таймер больше не нужен...
Vladimir Simakov: The object must contain a pointer to a class with a timer.
The question is how to run a non-static method of the class from the pointer, even if the object of another class (in this case CTimer) is a property (variable) of that class. Is it possible. I'm afraid not.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Has anyone come across a multi-timer solution so that I don't have to reinvent the wheel myself?
I don't see the implementation as being complicated by using pointers to the function. It is unlikely that it would not have already been implemented before me.
That is, the original task is to create a timer with any periodicity and assign to it a function to handle the timer event. And there can be any number of timers.
Like this:
No one has come across a multi-timer solution
I'm sure I've seen it at the Buy More a long time ago.
I can't find it. Strange.
OK, I'll implement it myself. Shouldn't be any pitfalls. I'll post it at the Buy More.
I.e. the initial task is to create a timer with any periodicity and map its timer event handling function to it. And there can be any number of timers.
simpler variant won't do?
UPD: And so, you can use fxsaber code as a template
here's how to make it so that all objects are automatically deleted https://www.mql5.com/ru/forum/325418/page4#comment_16116740
I can't find it. Weird.
OK, I'll implement it myself. Shouldn't be any pitfalls. I'll put it in the Buy More.
done
https://www.mql5.com/ru/code/31306
a simpler version wouldn't work?
UPD: otherwise, you can use fxsaber code as a template
here's how to make it so that all objects are automatically deleted https://www.mql5.com/ru/forum/325418/page4#comment_16116740
Of course, you could do it that way. But less readable and more difficult to manage.
made
https://www.mql5.com/ru/code/31306
Once upon a time (roughly) did this.
It's inconvenient to use with classes.
class CWithTimer {
public:
void CallMeByTimer();
};
And external (to the class) timer with pointers to the function is powerless.
once upon a time (roughly) did so.
It's inconvenient to use with classes.
class CWithTimer {
public:
void CallMeByTimer();
};
And external (to the class) timer with pointers to the function is powerless.
If you mean function as a class method, then yes, I agree. Figured it out myself yesterday and am puzzling over how to get out of it.
The object must contain a pointer to a class with a timer.