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

63 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.
# Insert
Inserts an element to the specified position in the array.
```
bool  Insert(
   CObject*  element,     // element to insert
   int       pos          // position
   )
```
Parameters
element
[in] Value of the element to be inserted into an array
pos
[in] Position in the array to insert
Return Value
true - successful, false - cannot insert the element.
Note
Element is not added to the array if an invalid pointer (such as NULL) is passed as a parameter.
Example:
```
//--- example for CArrayObj::Insert(CObject*,int)
#include <Arrays\ArrayObj.mqh>
//---
void OnStart()
  {
   CArrayObj *array=new CArrayObj;
   //---
   if(array==NULL)
     {
      printf("Object create error");
      return;
     }
   //--- insert elements
   for(int i=0;i<100;i++)
     {
      if(!array.Insert(new CObject,0))
        {
         printf("Insert error");
         delete array;
         return;
        }
     }
   //--- use array
   //--- . . .
   //--- delete array
   delete array;
  }
```