Files
mql5-skills/skills/mql5/references/docs/34-standardlibrary/1755-standardlibrary-datastructures-carrayobj-carrayobjcreateelement.md
T
2026-06-23 21:47:51 +08:00

60 lines
1.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CreateElement
Creates a new array element at the specified position.
```
bool  CreateElement(
   int  index      // position
   )
```
Parameters
index
[in] Position in which you want to create a new element.
Return Value
true - successful, false - cannot create an element.
Note
Method CreateElement (int) in class CArrayObj always returns false and does not perform any action. If necessary, the CreateElement(int) method should be implemented in a derived class.
Example:
```
//--- example for CArrayObj::CreateElement(int)
#include <Arrays\ArrayObj.mqh>
//---
void OnStart()
  {
   int        size=100;
   CArrayObj *array=new CArrayObj;
   //---
   if(array==NULL)
     {
      printf("Object create error");
      return;
     }
   //--- fill array
   array.Reserve(size);
   for(int i=0;i<size;i++)
     {
      if(!array.CreateElement(i))
        {
         printf("Element create error");
         delete array;
         return;
        }
     }
   //--- use array
   //--- . . .
   //--- delete array
   delete array;
  }
```