| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| MQL4 help needed: Access to class members in an array https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=6000 |
Page 1 of 1 |
| Author: | degoor1975 [ Fri Jan 29, 2021 1:05 pm ] |
| Post subject: | MQL4 help needed: Access to class members in an array |
I started to write an EA for the Empty4 platform and got stuck using class members in MQL4. I come from C# background where that thing is really easy to do. Hope someone will help me doing that in MQL4. So suppose I have a small class called #PivotPoint that has members called #Index & #PP. Then I would like to create an array from 6 instances of the #PivotPoint class and in the body of the EA I need to add and update those instances. After that {for testing purposes} I need to create dot objects on a chart from those pivot points. Here is a sample of my code: Code: Select all Obviously I can't access the members of the PivotPoint class in the array the way I am trying to. Hope you can give me a hand on that. Technically in the code above I can add new instance of the PivotPoint class and later draw the dot by only using #index_ and #high_. The problem is that later in my code {not included here} I need to update a previous instance of that class in the array so I still need to be able to access the members of that previous instance. EDIT: I have missed to include a line in #OnStart about #current_chart_id variable: Code: Select all |
|
| Author: | renexxxx [ Fri Jan 29, 2021 10:07 pm ] |
| Post subject: | MQL4 help needed: Access to class members in an array |
In order to avoid the "invalid pointer access" runtime error, you need to use the CheckPointer and GetPointer functions, as described in the docs. Besides, if you want to create an array of object pointers, it is much easier to use the CArrayObj class included with Empty4, eg. like this: Code: Select all |
|
| Author: | degoor1975 [ Sun Jan 31, 2021 8:07 am ] |
| Post subject: | MQL4 help needed: Access to class members in an array |
renexxxx, thanks for your answer. It turned out that the solution to my question is really simple: 1. When I need to create an instance of a class {as in the code above} I should do that like: Code: Select all Code: Select all Code: Select all |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|