Testing CGraphic - questions and suggestions - page 10

 

Forum on Trading, Automated Trading Systems and Strategy Tests

FAQ from Beginners MQL5 MT5 MetaTrader 5

Aleksey Vyazmikin, 2019.02.17 06:56

I decided to repeat the experiment again, here is the code

      //--- отключим показ ценового графика
      ChartSetInteger(0,CHART_SHOW,false);
      long chart=ChartID();

      CGraphic graphic;
         Print("0 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
      if(ObjectFind(chart,name)<0)
        {
         Print("1 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
         graphic.Create(chart,name,0,0,0,pix_X,pix_Y);//Создает графический ресурс, привязанный к объекту чарта 
         Print("2 Тут ошибка ",GetLastError()," ",cLng::CodeDescription(GetLastError()));
         ResetLastError();
        }

And here is result

2019.02.17 08:55:19.845 Test_4G_CB (Si Splice,H1)       0 Тут ошибка 0 Операция выполнена успешно
2019.02.17 08:55:19.860 Test_4G_CB (Si Splice,H1)       1 Тут ошибка 4202 Графический объект не найден
2019.02.17 08:55:19.860 Test_4G_CB (Si Splice,H1)       2 Тут ошибка 4202 Графический объект не найден
Any idea what caused the error?
I have been informed that the error is in the library - will it be fixed?
 
Aleksey Vyazmikin:
I have been informed that there is an error in the library - will it be corrected?

The telepaths are on holiday. And for ordinary people we need:

  1. minimal code (from which all unnecessary rubbish has been thrown out) that reproduces the problem.
  2. a clear description of what is wrong (what you want to get, what you get and why you think it is a bug)
  3. operating system specifications, terminal build, trade server name

 
Aleksey Vyazmikin:
I have been informed that there is an error in the library - will it be corrected?

Where were you told that there was an error? I told you - look for the point in the library where it may be written into the _LastError variable. It's not necessarily that the code with the error has worked. Because it might search for an object (and if it is absent, the error code will be written into the variable) and create it. But if object won't be created, it's an error, but it will be created and everything will work out. But after checking, the error code (the object was absent before creation) will be written into a variable, which you then read in your code.

 
Vladimir Karputov:

Telepaths are on holiday. What is needed for ordinary people is:

  1. minimal code (from which all unnecessary rubbish has been thrown out) that reproduces the problem.
  2. a clear description of what is wrong (what you wanted to get, what you got in the end and why you think it is an error)
  3. operating system specifications, terminal build, trade server name

1. Code

//+------------------------------------------------------------------+
//|                                              CB_Model_Analiz.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Graphics\Graphic.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   string name="Name";
   long chart=ChartID();

   CGraphic graphic;
   Print("0 Тут ошибка ",GetLastError());
   ResetLastError();
   if(ObjectFind(chart,name)<0)
     {
      Print("1 Тут ошибка ",GetLastError());
      ResetLastError();
      graphic.Create(chart,name,0,0,0,100,100);//Создает графический ресурс, привязанный к объекту чарта 
      Print("2 Тут ошибка ",GetLastError());
      ResetLastError();
     }
   graphic.Destroy();
  }
//+------------------------------------------------------------------+

2. No expectation of error messages in the log

2019.02.17 10:37:46.326 CB_Model_Analiz (Si Splice,H1)  1 Тут ошибка 4202
2019.02.17 10:37:46.326 CB_Model_Analiz (Si Splice,H1)  2 Тут ошибка 4202

3. Windows 7 Home 32 bit, build 1940, not connected to the server during testing - broker Discovery.

 
Artyom Trishkin:

Where have you been told that there is an error? I told you - look for a fragment in the library where it may be written into the _LastError variable. It's not necessarily that the code with the error worked. Because it might search for an object (and if it is absent, the error code will be written into the variable) and create it. But if object won't be created, then it's an error, but it will be created and everything will work out. But after checking, the error code (the object was absent before creation) will be written into a variable, which you then read in your code.

The library must either produce an error when there is an actual error, or correctly handle the situation and not produce an error where there is none. If my use of the library is not described in the class when checking for errors, you should specify it. At any rate, it's unreasonable for the user to edit the product's manufacturer's libraries.

 
Aleksey Vyazmikin:

The library must either produce an error when there is an actual error, or correctly handle the situation and not produce an error where there is none. If my use of the library is not described in the class when checking for errors, you should specify it. At any rate, it's unreasonable for the user to edit the product's manufacturer's libraries.

There is no error there, read it again:

Where were you told there was an error? I told you - look for a fragment in the library where it may be written into the _LastError variable. It's not necessarily that the code with the error has worked. Because it might search for an object (and if it is absent, the error code will be written into the variable) and create it. But if object won't be created, then it's an error, but it will be created and everything will work out. But after checking the error code (the object was absent before creation) will be written into a variable which you will then read in your code.

So it's only your interest to know why you read the error after the code's normal execution. What you do not understand is that the presence of code other than zero in the _LastError variable does not necessarily mean that there is an error in CGraphic's code and not only in it. In this case, it could be a simple result of searching for the existence of an object, which was executed inside the CGraphic in SB. There was a request for an object by name, the result returned -1 and code 4202 was written into _LastError. Then the object was created, everything worked and was returned to the calling program. And there you immediately read the error code and get it. But there is no error - you see the result of queries inside the SB.

I am only suggesting a possible reason for what you are reporting.

So, if you really want to find a real error and report it, you need to go through the whole CGraphic code in the debugger and catch the real error that will lead to logic and performance failures, rather than just claiming that you read the error code and therefore - it is definitely there.

 
Artyom Trishkin:

There is no error there, read it again:

So - it's only your interest to know why you're reading the error after the normal code execution. You probably do not understand that the content of the _LastError variable, which is not zero, does not necessarily mean that there is an error in the CGraphic code, and not only in it. In this case, it could be a simple result of searching for the existence of an object, which was executed inside the CGraphic in SB. There was a request for an object by name, the result returned -1 and code 4202 was written into _LastError. Then the object was created, everything worked and was returned to the calling program. And there you immediately read the error code and get it. But there is no error at all - you see the result of queries inside the SB.

I'm only suggesting a possible reason for what you're reporting.

So if you really want to find the real error and report it, then you need to go through the whole CGraphic code in the debugger and catch the real error that will cause the logic and operation to fail, rather than just claiming that you have read the error code and therefore - it is definitely there.

You yourself said in your logical reasoning that there could be an error in the code, and it is expressed in not resetting the error. which was received due to lack of an object before it was created.

No, I don't have the competence to look for an error in complex code and then get an answer that it was intended that way.

Can you please tell me if this message is a user error or not?

2019.02.17 11:08:42.901 Test_4G_CB (Si Splice,H1)       invalid pointer access in 'Test_4G_CB.mq5' (909,7)

The code that points to this isD.PointsFill(false);

      CCurve *D=graphicT.CurveAdd(X_04,Y_04,ColorToARGB(DarkOrange,256),CURVE_POINTS,Interval_04);//Создает и добавляет кривую на график
      D.PointsFill(false);//Устанавливает флаг, указывающий, нужно ли выполнять заливку для точек, определяющих кривую при отрисовке точками. 
      D.PointsType(POINT_VERTICAL_DASH);//Устанавливает флаг, указывающий на тип точек, использующихся при отрисовке кривой точками.
 
Aleksey Vyazmikin:

You yourself have indicated in your logical reasoning that there may be an error in the code, and it is expressed by not resetting the error. which was received due to the absence of the object before it was created.

No, I don't have the competence to look for an error in complex code and then get an answer that it was intended that way.

Can you please tell me if this message is a user error or not?

It points to this code -D.PointsFill(false);

I don't understand the meaning of the phrase at all.

It seems to me that I've already described everything to you in detail.

I don't know. Not much information.

 
Artyom Trishkin:

I don't understand the meaning of the phrase at all.

It seems to me that I have already explained everything to you in detail.

I don't know. Not much information.

You don't understand that if your code is built to react to an error (we create an object in case of an error), then after fixing the error(creating an object) it is logical to reset this error, which according to your logical reasoning is not done in the library.

Here I also don't have information how to react to this error...

 
Aleksey Vyazmikin:

You don't understand that if the code is built on error response (in case of error we create an object), then after error correction(object creation), it is logical to reset this error, which according to your logical reasoning is not done in the library.

Here I have no information on how to react to this error...

You must be well aware that it is not the code in _LastError that is not equal to zero that is an error, but the result returned by the function that indicates the erroneous execution of this function. And _LastError contains code that exactly points to that error which causes the function to execute by mistake. So it's doubtful that you can use the description of the error code stored in the service variable instead of using the return code of the function directly. If the function returned -1 or false or 0 (for each function its error code is described in the help), well - only the analysis of result returned by the function should be handled by you, not the code in _LastError, which doesn't indicate the error, but is used to indicate the cause of return of some result returned by the function.

The object search function returns a value less than zero in case an object with the given name doesn't exist. Is it an error? No. This is a standard response of the function, on the basis of which you make a decision about creating an object with the given name. The code contained in _LastError explicitly says that "An object with the requested name does not exist" - you can create it.

Well, I'm tired of explaining it to you. Whoever wants to, will understand.

Reason: