invalid pointer access

 

Hi

This error "invalid pointer access" is that I get from this code, any suggestion how to fix it?

#include<Arrays\List.mqh>

CList lineList;
class Line : public CObject 
{
public:
   string name;
   string description;
   double value;   
};

//... stuff
double p = 100.46;
Line *line = lineList.GetNodeAtIndex(i);
line.value = p; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<  invalid pointer access
 

samjesse:

any suggestion how to fix it?

Add a node into lineList.

lineList.Add(new Line());
 
Anthony Garot:

Add a node into lineList.

I need to modify a current item not to add a new one.

 
samjesse:

I need to modify a current item not to add a new one.

The error occurs because the node at index "i" doesn't exist.

Show the code where you add the nodes so we can see why this is the case.

Also, tack this into your code. It may reveal what's going on.

        Line *line = lineList.GetNodeAtIndex(i);
        PrintFormat("list count [%d] i [%d]", lineList.Total(), i);
        if ( line == NULL )
        {
                Print("line is null");
        }
        else
        {
                line.value = p;
        }
Reason: