Download MetaTrader 5

Error --> invalid array access --> structure have objects and cannot be copied

To add comments, please log in or register
Let your idle PCs do something useful. Join MQL5 Cloud Network!
avdarie
35
avdarie 2013.02.01 14:49 

Hi,

I try to do this code but appear the following errors messages:

       - invalid array access

       - structure have objects and cannot be copied


I try to do this function :

MqlParam XXXXSystem::GetParamsIndicator(int ind){

MqlParam Param[5];

return (Param);

}

Is possible return one Struct variable from Function ?

Regards,


Documentation on MQL5: Language Basics / Variables
Documentation on MQL5: Language Basics / Variables
  • www.mql5.com
Language Basics / Variables - Documentation on MQL5
phi nuts
2184
phi nuts 2013.02.02 03:10  
avdarie:

Hi,

I try to do this code but appear the following errors messages:

       - invalid array access

       - structure have objects and cannot be copied


I try to do this function :

MqlParam XXXXSystem::GetParamsIndicator(int ind){

MqlParam Param[5];

return (Param);

}

Is possible return one Struct variable from Function ?

Regards,

1. Next time, when posting a code, please use SRC button. It will help reading your code much easier.

 

2. Here the reason for "invalid array access", if - for example - the type of MqlParam is an integer type, you should tell the index of Param object and its struct member names, like this

return (Param[0].interger_value); 

Zero in Param[0] is an index for the array, and integer_value is a member of MqlParam

3. I could not correctly give answer for the other error, because you're only posting some part of your code.

avdarie
35
avdarie 2013.02.03 12:27  

Thank you very much for the reply!

I solved the problem redefining my Struct I changed variable where this kept ParamsIndicator to MqlParam! This had them stored in an array but I changed in MqlParam, I think it is better to define it in MqlParam! Easy for access and use variables with IndicatorCreate!

But the problem was commenting if a function can return a different value than (string, number,double... ) for exampel one struct. In this exampel I tried to return all struct variable (Param) . An my question was That is posible?

I'm a rookie in  MQL5 programming :).

Regards
!



Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure of Input Parameters
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure of Input Parameters
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Structure of Input Parameters - Documentation on MQL5
phi nuts
2184
phi nuts 2013.02.03 23:55  
avdarie:

Thank you very much for the reply!

I solved the problem redefining my Struct I changed variable where this kept ParamsIndicator to MqlParam! This had them stored in an array but I changed in MqlParam, I think it is better to define it in MqlParam! Easy for access and use variables with IndicatorCreate!

But the problem was commenting if a function can return a different value than (string, number,double... ) for exampel one struct. In this exampel I tried to return all struct variable (Param) . An my question was That is posible?

I'm a rookie in  MQL5 programming :).

Regards
!

1. I consider myself a rookie too :). I don't remember all mql5 function and what the purpose of it. So I have to re-read the doc agai and again and re-test and re-experimenting with my MT.

2. Any function can only return one value, though we can manipulate it by passing parameter as reference and not by value (click here) , but since you using a struck, why don't make that struck globally-declared-struck, therefore you can access its member from anywhere.

avdarie
35
avdarie 2013.02.04 13:32  

Yes,  I can Do that (2).  I can create globally-declared-struck.

But I found that https://www.mql5.com/en/forum/631 this user have sem question.

Now I having solved problem :) 

Thanks very much!!

(Bug) Functions that returns struct
(Bug) Functions that returns struct
  • www.mql5.com
The compilation goes with no error, but the code simply doesn't run, no error alert of any kind, the code simply does nothing.
phi nuts
2184
phi nuts 2013.02.04 14:38  
avdarie:

Yes,  I can Do that (2).  I can create globally-declared-struck.

But I found that https://www.mql5.com/en/forum/631 this user have sem question.

Now I having solved problem :) 

Thanks very much!!

That is called : passed by reference (notice the ampersand sign "&") ;D
avdarie
35
avdarie 2013.02.05 20:26  

jejeje I know that ! But the problem is when use in function return(struct)  :/
phi nuts
2184
phi nuts 2013.02.06 15:00  
avdarie:

jejeje I know that ! But the problem is when use in function return(struct)  :/

I had a felling that I should gave an example, but I was busy at that time :(, but anyway, thanks for searching, coz I didn't search :( and gives us that link to old post  :).

That was before I become mod. 

avdarie
35
avdarie 2013.02.12 14:30  

No problem ! I'm solved problem maybe when you have time can write one exemplel. Thank you very much ! :)

To add comments, please log in or register