Errors, bugs, questions - page 2471
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Explain why when I create CChartObjectLabel I am not deleting objects in indicator when deinitializing in this code:
when switching TF I get journal entry: 2019.05.23 09:49:02.044 tstlabel EURUSD,M30: 2 objects of type CChartObjectLabel left
if uncommented in OnInit() the creation of text labels (CChartObjectLabel), then everything will work correctly
I pass a pointer to theCreateLabel() function, butI can'tdelete it later inOnDeinit()
A new l object is created. And it is not deleted.
logically
But the scope ofCChartObjectLabel *LabelUP,*LabelDN; variables is global?
So I can modify the variable at any point in the code?
I pass a pointer to the CreateLabel() function, why do I create a new copy?
imho, it's not working correctly.
HH: If I create objects in OnInit() and then work with them in CreateLabel() (that is, I create the objects separately and work with them by pointer), everything will work correctly - but I do not remember a case in other compilers to pass a pointer to a function to create a new object - a pointer, he is a pointer!
logically
but my scope is global? - it means i can modify a variable in any part of my code ?
I pass a pointer to CreateLabel(), why do I get a new copy?
Imho, it doesn't work correctly.
logically
But the scope ofCChartObjectLabel *LabelUP,*LabelDN; variables is global?
So I can modify the variable at any point in the code?
I pass a pointer to the CreateLabel() function, why do I create a new copy?
Imho, it doesn't work correctly
Reassigning a pointer to a new object, we loose the previous object, which was pointed by the reassigned pointer.
no, a pointer is a pointer, in MQL it's a descriptor, not the point - but it's not correct to create a new copy of the object, this works correctly now:
but if you follow your logic, then this code will also create a copy of object l in the function SetLabel() - i passed a pointer, not a reference?
new should be removed. The objects already exist and so do the pointers to them.
the question is not how to solve the problem, but why in the global scope of the variableCChartObjectLabel *LabelUP,*LabelDN;- lost the pointer!
no, a pointer is a pointer, in MQL it's a descriptor, not the point - but it's not correct to create a new copy of the object, this works correctly now:
but if you follow your logic, then this code will also create a copy of object l in the function SetLabel() - I passed a pointer, not a reference?
No. Here l is the method parameter through which we pass the needed pointer. Everything is ok here. The pointer here stays on the earlier created object. Here we don't create a new object and reassign the pointer to it with the loss of the previous object.
it still doesn't work correctly
these "pointers" in MQL are made to work in the scope of the class, I don't want to create a class, I declare a global pointer and then pass it to any function, and the fact that in this function I create a descriptor of the object is not the reason to destroy the object upon exiting the local scope of the function
I'm a little busy right now, but I need to make test examples without graphics - I think the same thing will happen if you entered the function with a pointer with POINTER_INVALID value, you will exit with the same POINTER_INVALID , by reference, everything will work correctly, but it seems you can't pass a pointer with POINTER_INVALID by reference - there will be an error accessing the pointer
everything doesn't work correctly anyway
these "pointers" in MQL are made to work in the scope of the class, I don't want to create a class, I just drill and declare a pointer in the global scope, then pass it to any function and the fact that I create an object handle in this function is not the reason to destroy the object upon exiting the local scope of the function
I think it will be the same problem, if you come in with POINTER_INVALID value in this function, you will exit with the same POINTER_INVALID value , by reference, everything will work correctly, but it seems that you can not pass a POINTER_INVALID value in this function - there will be an error when accessing the pointer
I was surprised to find that it was possible to declare typedef with a pointer to a template function.
However, the happiness did not last long.
Is typedef with a pointer to a template function a planned feature?
When working with typedef, using a template function with explicit specialisation does not generate code for that template