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

75 lines
1.6 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.
# InsertArray
Inserts elements of one array from the specified position of another array.
```
bool  InsertArray(
   const CArrayObj*  src,     // pointer to the source
   int               pos      // position
   )
```
Parameters
src
[in] Pointer to an instance of the CArrayObj class used as a source of elements to insert.
pos
[in] Position in the array to insert
Return Value
true - successful, false - cannot insert items.
Note
See: [CArrayObj::AddArray(const CArrayObj*)](/en/docs/standardlibrary/datastructures/carrayobj/carrayobjaddarray#addarrayremark).
Example:
```
//--- example for CArrayObj::InsertArray(const CArrayObj*,int)
#include <Arrays\ArrayObj.mqh>
//---
void OnStart()
  {
   CArrayObj *array=new CArrayObj;
   //---
   if(array==NULL)
     {
      printf("Object create error");
      return;
     }
   //--- create source array
   CArrayObj *src=new CArrayObj;
   if(src==NULL)
     {
      printf("Object create error");
      delete array;
      return;
     }
   //--- reset free mode flag
   src.FreeMode(false);
   //--- fill source array
   //--- . . .
   //--- insert another array
   if(!array.InsertArray(src,0))
     {
      printf("Array inserting error");
      delete src;
      delete array;
      return;
     }
   //--- delete source array without elements
   delete src;
   //--- use array
   //--- . . .
   //--- delete array
   delete array;
  }
```