//////////////////////////////////////////////////////////////////////////////// 
// 
// step2a.cpp -   
// 
// 1.                             - StrIndefiniteArray 
// 2.               - PointIndefiniteArray 
// 3.    ""           - TextIndefiniteArray 
// 4.               - AttrIndefiniteArray 
// 5.                         - PolyLineArray 
// 6.         - RectArray 
// 7.              - UserDataArray
// 8.     - UserClassArray
// 
//////////////////////////////////////////////////////////////////////////////// 
#ifndef __WINDOWS_H 
#include <windows.h>
#endif

#ifndef __STDIO_H
#include <stdio.h>
#endif

#ifndef __STRING_H
#include <string.h>
#endif

#ifndef __STDLIB_H
#include <stdlib.h>
#endif

#ifndef __LIBTOOL_H
#include "libtool.h"
#endif

#ifndef __STEP2A_RH
#include "step2a.rh"
#endif 


//-------------------------------------------------------------------------------
//   
// ---
extern "C" unsigned int __export __pascal LIBRARYID()
{
  return IDR_LIBID;
}


//-------------------------------------------------------------------------------
//   
// ---
void PointIndefiniteArray();
void TextIndefiniteArray();
void StrIndefiniteArray();
void AttrIndefiniteArray();
void PolyLineArray();
void RectArray();
void UserDataArray();
void UserClassArray();


//-------------------------------------------------------------------------------
//   
// ---
extern "C" void __export __pascal LIBRARYENTRY( unsigned int comm )
{
  switch ( comm )
  {
    case 1 : StrIndefiniteArray();   break; //  
    case 2 : PointIndefiniteArray(); break; //   
    case 3 : TextIndefiniteArray();  break; //    ""
    case 4 : AttrIndefiniteArray();  break; //    
    case 5 : PolyLineArray();        break; //  
    case 6 : RectArray();            break; //   
    case 7 : UserDataArray();        break; //   
    case 8 : UserClassArray();       break; //    
  }
}


//--------------------------------------------------------------------------
//         , 
//      ,    
//   ,   
// (  ,  ,   . . )
// ---
void TextIndefiniteArray()
{
  TextItemParam parTextItem; //     
  TextLineParam parTextLine; //    
  
  //    
  reference rArTextLine = CreateArray( TEXT_LINE_ARR, 0 );

  //    
  reference rArTextItem = CreateArray( TEXT_ITEM_ARR, 0 );

  //    
  //  1-  
  parTextItem.font.height    = 10;   //  
  parTextItem.font.ksu       = 1;    // C 
  parTextItem.font.color     = 1000; // 
  parTextItem.font.bitVector = 1;    //   ( , , ,   ( , ,    ) )
  lstrcpy( parTextItem.s, "1  1 " ); //  
  //  1-    ,     
  AddArrayItem( rArTextItem,             //   
                -1,                      //   
                &parTextItem,            //    
                sizeof( parTextItem ) ); //   
  
  //  2-  
  parTextItem.font.height    = 20;   //  
  parTextItem.font.ksu       = 2;    //  
  parTextItem.font.color     = 2000; // 
  parTextItem.font.bitVector = 2;    //   ( , , ,   ( , ,    ) )
  lstrcpy( parTextItem.s, "2  1 " ); //  
  //  2-    ,     
  AddArrayItem( rArTextItem,             //   
                -1,                      //   
                &parTextItem,            //    
                sizeof( parTextItem ) ); //   
  // 1-             
  parTextLine.style     = 1;           //    	
  parTextLine.pTextItem = rArTextItem; //       
  //   ,     
  AddArrayItem( rArTextLine,             //   
                -1,                      //   
                &parTextLine,            //    
                sizeof( parTextLine ) ); //     

  //   ,     2-  
  ClearArray( rArTextItem );

  //    
  //  1-  
  parTextItem.font.height    = 30;   //  
  parTextItem.font.ksu       = 3;    //  
  parTextItem.font.color     = 3000; // 
  parTextItem.font.bitVector = 3;    //   ( , , ,   ( , ,    ) )
  lstrcpy( parTextItem.s, "1  2 " ); //  
  //  1-    ,     
  AddArrayItem( rArTextItem,             //   
                -1,                      //   
                &parTextItem,            //    
                sizeof( parTextItem ) ); //       

  //  2-  
  parTextItem.font.height    = 40;   //  
  parTextItem.font.ksu       = 4;    //  
  parTextItem.font.color     = 4000; // 
  parTextItem.font.bitVector = 4;    //   ( , , ,   ( , ,    ) )
  lstrcpy( parTextItem.s, "2  2 " ); //  
  //  2-    ,     
  AddArrayItem( rArTextItem,             //   
                -1,                      //   
                &parTextItem,            //    
                sizeof( parTextItem ) ); //     
                
  // 2-             
  parTextLine.style     = 2;           //    	
  parTextLine.pTextItem = rArTextItem; //       
  //   ,     
  AddArrayItem( rArTextLine,             //   
                -1,                      //   
                &parTextLine,            //    
                sizeof( parTextLine ) ); //     
                
  //     
  int count = GetArrayCount( rArTextLine );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );

  //    
  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArTextLine,             //   
                  i,                       //   
                  &parTextLine,            //    
                  sizeof( parTextLine ) ); //     
    sprintf( buf, "i = %d, style = %d", i, parTextLine.style );
    Message( buf );

    //     
    int count1 = GetArrayCount( rArTextItem );
    
    //     
    for ( int j = 0; j < count1; j++ )
    {
      //    
      GetArrayItem( rArTextItem,             //   
                    j,                       //   
                    &parTextItem,            //    
                    sizeof( parTextItem ) ); //     
      sprintf( buf, "j = %d, font.height = %4.2f, s = %s", j, parTextItem.font.height, parTextItem.s );
      Message( buf );
    }
  }
  
  //      
  //    
  GetArrayItem( rArTextLine,             //   
                0,                       //   
                &parTextLine,            //    
                sizeof( parTextLine ) ); //     
  parTextItem.font.height    = 50;   //  
  parTextItem.font.ksu       = 1;    //  
  parTextItem.font.color     = 1000; // 
  parTextItem.font.bitVector = 1;    //   ( , , ,   ( , ,    ) )
  lstrcpy( parTextItem.s, "2 . 1 ." ); //  
  //      
  SetArrayItem( rArTextItem,             //   
                1,                       //   
                &parTextItem,            //    
                sizeof( parTextItem ) ); //     
                
  parTextLine.style = 3; //    	
  //       
  SetArrayItem( rArTextLine,             //   
                0,                       //   
                &parTextLine,            //    
                sizeof( parTextLine ) ); //     

  //      
  //    
  GetArrayItem( rArTextLine,             //   
                1,                       //   
                &parTextLine,            //    
                sizeof( parTextLine ) ); //     
  parTextItem.font.height    = 60;   //  
  parTextItem.font.ksu       = 1;    //  
  parTextItem.font.color     = 1000; // 
  parTextItem.font.bitVector = 1;    //   ( , , ,   ( , ,    ) )
  lstrcpy( parTextItem.s, "1 . 2 ." ); //  
  //      
  SetArrayItem( rArTextItem,             //   
                0,                       //   
                &parTextItem,            //    
                sizeof( parTextItem ) ); //     
                
  parTextLine.style = 4; //    	
  //       
  SetArrayItem( rArTextLine,             //   
                1,                       //   
                &parTextLine,            //    
                sizeof( parTextLine ) ); //     

  //     
  count = GetArrayCount( rArTextLine );
  
  //    
  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArTextLine,             //   
                  i,                       //   
                  &parTextLine,            //    
                  sizeof( parTextLine ) ); //     
    sprintf( buf, "i = %d, style = %d", i, parTextLine.style );
    Message( buf );

    //     
    int count1 = GetArrayCount( rArTextItem );
    
    //     
    for ( int j = 0; j < count1; j++ )
    {
      //    
      GetArrayItem( rArTextItem,             //   
                    j,                       //   
                    &parTextItem,            //    
                    sizeof( parTextItem ) ); //     
      sprintf( buf, "j = %d, font.height = %4.2f, s = %s", j, parTextItem.font.height, parTextItem.s );
      Message( buf );
    }
  }

  DeleteArray( rArTextItem ); //    
  DeleteArray( rArTextLine ); //     
}


//--------------------------------------------------------------------------
//        MathPointParam
// ---
void PointIndefiniteArray()
{
  MathPointParam parMathPoint; //        
  
  // C     
  reference rArMathPoint = CreateArray( POINT_ARR, 0 );
  
  //    
  parMathPoint.x = 10; 
  parMathPoint.y = 10;
  //  1- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //       
  
  parMathPoint.x = 20;
  parMathPoint.y = 20;
  //  2- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //     
                  
  parMathPoint.x = 30;
  parMathPoint.y = 30;
  //  3- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //       
  
  //       
  int count = GetArrayCount( rArMathPoint );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );
 
  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArMathPoint,             //   
                  i,                        //   
                  &parMathPoint,            //    
                  sizeof( parMathPoint ) ); //     
    sprintf( buf, "i = %d, x = %4.2f, y = %4.2f", i, parMathPoint.x, parMathPoint.y );
    Message( buf );
  }
  
  //   1-    
  parMathPoint.x = 50; 
  parMathPoint.y = 50;
  SetArrayItem( rArMathPoint,             //    
                1,                        //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //     
 
  //   0-    
  parMathPoint.x = 60; 
  parMathPoint.y = 60;
  SetArrayItem( rArMathPoint,             //   
                0,                        //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //     
 
  //       
  count = GetArrayCount( rArMathPoint );
  
  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArMathPoint,             //   
                  i,                        //   
                  &parMathPoint,            //    
                  sizeof( parMathPoint ) ); //     
    sprintf( buf, "i = %d, x = %4.2f, y = %4.2f", i, parMathPoint.x, parMathPoint.y );
    Message( buf );
  }

  DeleteArray( rArMathPoint ); //     
}


//--------------------------------------------------------------------------
//     
// ---
void StrIndefiniteArray()
{
  //     
  reference rArString = CreateArray( CHAR_STR_ARR, 0 );
  
  //   
  char buf[255];
  strcpy( buf, "12345" );
  //  1- ,     
  AddArrayItem( rArString,       //   
                -1,              //   
                &buf,            //    
                sizeof( buf ) ); //     
                  
  strcpy( buf, "67890" );
  //  2- ,     
  AddArrayItem( rArString,       //   
                -1,              //   
                &buf,            //    
                sizeof( buf ) ); //      
  
  strcpy( buf, "qwerty" );
  //  3- ,     
  AddArrayItem( rArString,       //   
                -1,              //   
                &buf,            //    
                sizeof( buf ) ); //     
 
  //     
  int count = GetArrayCount( rArString );
  sprintf( buf, "count = %d", count );
  Message( buf );
 
  //   
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArString,       //   
                  i,               //   
                  buf,             //    
                  sizeof( buf ) ); //     
    Message( buf );
  }
 
  //    1- 
  ExcludeArrayItem( rArString, 1 );
  
  //     
  count = GetArrayCount( rArString );
  
  //   
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArString,       //   
                  i,               //   
                  buf,             //    
                  sizeof( buf ) ); //     
    Message( buf );
  }

  DeleteArray( rArString ); //    
}


//-------------------------------------------------------------------------------
//     
// ---
void ShowColumns( reference rArColumn, bool record )
{
  ColumnInfo parColumn; //     
    
  //   
  parColumn.columns   = CreateArray( ATTR_COLUMN_ARR, 0 ); //        
  parColumn.fieldEnum = CreateArray( CHAR_STR_ARR, 0 );    //        

  //     
  int count = GetArrayCount( rArColumn );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );
  
  //   
  for ( int i = 0; i < count; i++ )
  {
    //    
    if ( !GetArrayItem( rArColumn,              //   
                        i,                      //   
                        &parColumn,             //    
                        sizeof( parColumn ) ) ) //     
      MessageBoxResult(); //       
    else
    {
      //    
      sprintf( buf, record ? "RECORD, i = %d, header = %s,\ntype = %d, def = %s, flagEnum = %d" : 
                             "i = %d, header = %s,\ntype = %d, def = %s, flagEnum = %d", 
               i, parColumn.header, parColumn.type, parColumn.def, parColumn.flagEnum );
      Message( buf );
      
      //      - ( RECORD ),   columns   
      //  ,    . 
      
      if ( parColumn.type == RECORD_ATTR_TYPE ) //   
        ShowColumns( parColumn.columns, TRUE );
      else
      {
        //   
        if ( parColumn.flagEnum )
        {
          //     
          int count1 = GetArrayCount( parColumn.fieldEnum );
          
          Message( " " );
          for ( int j = 0; j < count1; j++ )
          {
            //    
            if ( !GetArrayItem( parColumn.fieldEnum, //   
                                j,                   //   
                                &buf,                //    
                                sizeof( buf ) ) )    //     
              MessageBoxResult(); //       
            else
              Message( buf );
          }
        }
      }
    }
  }
  
  //   
  DeleteArray( parColumn.columns );   //        
  DeleteArray( parColumn.fieldEnum ); //        
}


//--------------------------------------------------------------------------
//        , 
//      
// ---
void AttrIndefiniteArray()
{
  //    3 
  //   -  int    ( 100, 200, 300 )
  //   -    double (   123456789 )
  //                                                 long   (   1000000 )
  //                                                 char   (   10 )
  //   -   (   "text" )

  ColumnInfo parColumn1, //     
             parColumn2, //    
             parColumn3, //    
             parStruct;  //     
  
  //   
  reference rArColumn = CreateArray( ATTR_COLUMN_ARR, 0 ); //   
  reference rArStruct = CreateArray( ATTR_COLUMN_ARR, 0 ); //    
  reference rArEnum   = CreateArray( CHAR_STR_ARR, 0 );    //    

  //  
  strcpy( parColumn1.header, "int" ); // o- 
  parColumn1.type = INT_ATTR_TYPE;    //     - .
  parColumn1.key = 0;                 //  ,        
  strcpy( parColumn1.def, "100" );    //   
  parColumn1.flagEnum = 1;            //   ,      
                                      //     1  0 
  parColumn1.fieldEnum = rArEnum;     //        
  parColumn1.columns = 0;             //        

  //       ,     
  char buf[255];
  strcpy( buf, "100" );
  //  1- ,     
  AddArrayItem( rArEnum,         //   
                -1,              //   
                &buf,            //    
                sizeof( buf ) ); //     
                  
  strcpy( buf, "200" );
  //  2- ,     
  AddArrayItem( rArEnum,         //   
                -1,              //   
                &buf,            //    
                sizeof( buf ) ); //     
  
  strcpy( buf, "300" );
  //  3- ,     
  AddArrayItem( rArEnum,         //   
                -1,              //   
                &buf,            //    
                sizeof( buf ) ); //     

  //   ,     
  AddArrayItem( rArColumn,              //   
                -1,                     //   
                &parColumn1,            //    
                sizeof( parColumn1 ) ); //     
                
  //      - ( RECORD ),   columns   
  //  ,    . 
      
  //  
  strcpy( parColumn2.header, "struct" ); // o- 
  parColumn2.type = RECORD_ATTR_TYPE;    //     - .
  parColumn2.key = 0;                    //  ,        
  parColumn2.def[0] = '\0';              //   
  parColumn2.flagEnum = 0;               //   ,      
                                         //     1  0 
  parColumn2.fieldEnum = 0;              //        
  parColumn2.columns = rArStruct;        //        
 
  //     
  //   
  strcpy( parStruct.header, "double" ); // o- 
  parStruct.type = DOUBLE_ATTR_TYPE;    //     - .
  parStruct.key = 0;                    //  ,        
  strcpy( parStruct.def, "123456789" ); //   
  parStruct.flagEnum = 0;               //   ,      
                                        //     1  0 
  parStruct.fieldEnum = 0;              //        
  parStruct.columns = 0;                //          
  //    ,     
  AddArrayItem( rArStruct,             //   
                -1,                    //   
                &parStruct,            //    
                sizeof( parStruct ) ); //     
                
  //   
  strcpy( parStruct.header, "long" ); // o- 
  parStruct.type = LINT_ATTR_TYPE;    //     - .
  parStruct.key = 0;                  //  ,        
  strcpy( parStruct.def, "1000000" ); //   
  parStruct.flagEnum = 0;             //   ,      
                                      //     1  0 
  parStruct.fieldEnum = 0;            //        
  parStruct.columns = 0;              //        
  //    ,     
  AddArrayItem( rArStruct,             //   
                -1,                    //   
                &parStruct,            //    
                sizeof( parStruct ) ); //     
                
  //   
  strcpy( parStruct.header, "char" ); // o- 
  parStruct.type = CHAR_ATTR_TYPE;    //     - .
  parStruct.key = 0;                  //  ,        
  strcpy( parStruct.def, "10" );      //   
  parStruct.flagEnum = 0;             //   ,      
                                      //     1  0 
  parStruct.fieldEnum = 0;            //        
  parStruct.columns = 0;              //        
  //    ,     
  AddArrayItem( rArStruct,             //   
                -1,                    //   
                &parStruct,            //    
                sizeof( parStruct ) ); //     
                  
  //   ,     
  AddArrayItem( rArColumn,              //   
                -1,                     //   
                &parColumn2,            //    
                sizeof( parColumn2 ) ); //     
                
  //   
  strcpy( parColumn3.header, "string" ); // o- 
  parColumn3.type = STRING_ATTR_TYPE;    //     - .
  parColumn3.key = 0;                    //  ,        
  strcpy( parColumn3.def, "text" );      //   
  parColumn3.flagEnum = 0;               //   ,      
                                         //     1  0 
  parColumn3.fieldEnum = 0;              //        
  parColumn3.columns = 0;                //        
  
  //   ,     
  AddArrayItem( rArColumn,              //   
                -1,                     //   
                &parColumn3,            //    
                sizeof( parColumn3 ) ); //     
                
  //   
  ShowColumns( rArColumn, FALSE ); 

  //    2->1, 1->3, 3->2 (   )
  SetArrayItem( rArColumn,              //   
                0,                      //   
                &parColumn2,            //    
                sizeof( parColumn2 ) ); //     
                
  SetArrayItem( rArColumn,              //   
                2,                      //   
                &parColumn1,            //    
                sizeof( parColumn1 ) ); //     
                
  SetArrayItem( rArColumn,              //   
                1,                      //   
                &parColumn3,            //    
                sizeof( parColumn3 ) ); //     

  //   
  ShowColumns( rArColumn, FALSE );

  //   
  DeleteArray( rArColumn ); //   
  DeleteArray( rArStruct ); //    
  DeleteArray( rArEnum );   //      
}


//-------------------------------------------------------------------------------
//  
// ---
struct UserData 
{
  int i;
  char * c;
  float f;
};


//-------------------------------------------------------------------------------
//    UserData -  
// ---
void __stdcall DelFuncUserData( void * val )
{
  UserData * tmp = ( UserData * )val;
  char buf[255];
  sprintf( buf, " \nc = %s", tmp->c );
  Message( buf );
  delete [] tmp->c;
  delete tmp;
}
 

//-------------------------------------------------------------------------------
//    UserData -  
// ---
int AddUserData( reference rArray, int i, char * c, float f )
{
  UserData * tmp = new UserData;
  tmp->i = i;
  tmp->c = new char[strlen( c ) + 1];
  strcpy( tmp->c, c );
  tmp->f = f;
  //     
  return AddArrayItem( rArray,               //   
                       -1,                   //   
                       tmp,                  //    
                       sizeof( UserData ) ); //     
}


//-------------------------------------------------------------------------------
//     UserData -  
// ---
void ShowUserData( UserData & tmp )
{
  char buf[255];
  sprintf( buf, "i = %d,\nf = %f,\nc = %s", tmp.i, tmp.f, tmp.c );
  Message( buf );
}


//------------------------------------------------------------------------------
//     
// ---
void UserDataArray()
{
  //    
  UserData * tmp;
  
  //      , DelFuncUserData 
  //     
  reference rArUserData = CreateArray( USER_ARR, DelFuncUserData );

  //     
  if ( !AddUserData( rArUserData, 1, "", 31. ) )
    MessageBoxResult(); //       
  if ( !AddUserData( rArUserData, 2, "", 29. ) )
    MessageBoxResult(); //       
  if ( !AddUserData( rArUserData, 3, "", 31. ) )
    MessageBoxResult(); //       

  //      
  int count = GetArrayCount( rArUserData );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );
  
  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    if ( !GetUserArrayItem( rArUserData, i, ( void** )&tmp ) )
      MessageBoxResult(); //       
    else 
      ShowUserData( *tmp );
  }
  
  //     
  DeleteArray( rArUserData );
}


//-------------------------------------------------------------------------------
//  
// ---
class UserClass
{
private :
  int *i;
  char *c;
  double *d;
public :
  UserClass(): i( NULL ), c( NULL ), d( NULL ){};
  UserClass( int _i, char *_c, double _d );
  ~UserClass();
  void Show();
};


//-------------------------------------------------------------------------------
//   - 
// ---
UserClass::UserClass( int _i, char *_c, double _d )
{
  i = new int;
  *i = _i;
  c = new char [strlen( _c )+1];
  strcpy( c, _c );
  d = new double;
  *d = _d;
}


//-------------------------------------------------------------------------------
//   - 
// ---
UserClass::~UserClass()
{
  delete i;
  char buf[255];
  sprintf( buf, " \nc = %s", c );
  Message( buf );  
  delete [] c;
  delete d;
}


//-------------------------------------------------------------------------------
//   -  
// ---
void UserClass::Show()
{
  char buf[255];
  sprintf( buf, "i = %d,\nd = %f,\nc = %s", *i, *d, c );
  Message( buf );
}


//-------------------------------------------------------------------------------
//    UserClass -  
// ---
void __stdcall DelFuncUserClass( void * val )
{
  UserClass * tmp = ( UserClass * ) val;
  delete tmp;
}


//-------------------------------------------------------------------------------
//    UserClass -  
// ---
int AddUserClass( reference rArray, int i, char *c, double d )
{
  UserClass * tmp = new UserClass( i, c, d );
  //      
  return AddArrayItem( rArray,                //   
                       -1,                    //   
                       tmp,                   //    
                       sizeof( UserClass ) ); //      
}


//------------------------------------------------------------------------------
//      
// ---
void UserClassArray()
{
  //    
  UserClass * tmp;
  
  //     , DelFuncUserClass 
  //     
  reference rArUserClass = CreateArray( USER_ARR, DelFuncUserClass );
  //     
  if ( !AddUserClass( rArUserClass, -10, "First",  10031. ) )
    MessageBoxResult(); //       
  if ( !AddUserClass( rArUserClass, -20, "Second", 10029. ) )
    MessageBoxResult(); //       
  if ( !AddUserClass( rArUserClass, -30, "Third",  10031. ) )
    MessageBoxResult(); //       

  //       
  int count = GetArrayCount( rArUserClass );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );
    
  //     
  for ( int i = 0; i < count; i++ )
  {
    //    
    if ( !GetUserArrayItem( rArUserClass, i, ( void** )&tmp ) )
      MessageBoxResult(); //       
    else 
      tmp->Show();
  }

  //      
  DeleteArray( rArUserClass );
}


//-------------------------------------------------------------------------------
//       
// ---
void PolyLineArray()
{
  MathPointParam parMathPoint; //        
  
  reference rArMathPoint = CreateArray( POINT_ARR, 0 );    //     
  reference rArPolyLine  = CreateArray( POLYLINE_ARR, 0 ); //   -   

  //    
  parMathPoint.x = 10; 
  parMathPoint.y = 10;
  //  1- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
                         
  parMathPoint.x = 100;
  parMathPoint.y = 100;
  //  2- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
  
  parMathPoint.x = 1000;
  parMathPoint.y = 1000;
  //  3- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    

  //  1-      ,     
  AddArrayItem( rArPolyLine,              //   
                -1,                       //   
                &rArMathPoint,            //    
                sizeof( rArMathPoint ) ); //    
                
  //    ,     2- 
  ClearArray( rArMathPoint );

  //    
  parMathPoint.x = 20; 
  parMathPoint.y = 20;
  //  1- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
                  
  parMathPoint.x = 200;
  parMathPoint.y = 200;
  //  2- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
  
  parMathPoint.x = 2000;
  parMathPoint.y = 2000;
  //  3- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
  
  //  2-      ,     
  AddArrayItem( rArPolyLine,              //   
                -1,                       //   
                &rArMathPoint,            //    
                sizeof( rArMathPoint ) ); //      

  //    ,     3- 
  ClearArray( rArMathPoint );
  
  //    
  parMathPoint.x = 30; 
  parMathPoint.y = 30;
  //  1- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
  
  parMathPoint.x = 300;
  parMathPoint.y = 300;
  //  2- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
  
  parMathPoint.x = 3000;
  parMathPoint.y = 3000;
  //  3- ,     
  AddArrayItem( rArMathPoint,             //   
                -1,                       //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //    
  
  //  3-      ,     
  AddArrayItem( rArPolyLine,              //   
                -1,                       //   
                &rArMathPoint,            //    
                sizeof( rArMathPoint ) ); //    

  //     
  int count = GetArrayCount( rArPolyLine );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );
 
  //   
  //    -   
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArPolyLine,              //   
                  i,                        //   
                  &rArMathPoint,            //    
                  sizeof( rArMathPoint ) ); //     

    //       
    int count1 = GetArrayCount( rArMathPoint );
    
    //    -   
    for ( int j = 0; j < count1; j++ )
    {
      //    
      GetArrayItem( rArMathPoint,             //   
                    j,                        //   
                    &parMathPoint,            //    
                    sizeof( parMathPoint ) ); //     
      sprintf( buf, "i = %d, x = %4.2f, y = %4.2f", i, parMathPoint.x, parMathPoint.y );
      Message( buf );
    }
  }

  //      (    )  
  //     
  GetArrayItem( rArPolyLine,              //   
                1,                        //   
                &rArMathPoint,            //    
                sizeof( rArMathPoint ) ); //     
  
  //      
  GetArrayItem( rArMathPoint,             //   
                1,                        //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //       
  
  parMathPoint.x = 500;
  parMathPoint.y = 500;
  //        
  SetArrayItem( rArMathPoint,             //   
                1,                        //   
                &parMathPoint,            //    
                sizeof( parMathPoint ) ); //     

  //      
  SetArrayItem( rArPolyLine,              //   
                1,                        //   
                &rArMathPoint,            //    
                sizeof( rArMathPoint ) ); //     

  //     
  count = GetArrayCount( rArPolyLine );
 
  //   
  //    -   
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArPolyLine,              //   
                  i,                        //   
                  &rArMathPoint,            //    
                  sizeof( rArMathPoint ) ); //     

    //       
    int count1 = GetArrayCount( rArMathPoint );
    
    //    -   
    for ( int j = 0; j < count1; j++ )
    {
      //    
      GetArrayItem( rArMathPoint,             //   
                    j,                        //   
                    &parMathPoint,            //    
                    sizeof( parMathPoint ) ); //     
      sprintf( buf, "i = %d, x = %4.2f, y = %4.2f", i, parMathPoint.x, parMathPoint.y );
      Message( buf );
    }
  }

  //   
  DeleteArray( rArMathPoint ); //     
  DeleteArray( rArPolyLine );  //   -   
}


//--------------------------------------------------------------------------------
//     (  RectParam )
// ---
void RectArray()
{
  RectParam parRect; //      
  
  //     
  reference rArRect = CreateArray( RECT_ARR, 0 );
  
  //     
  parRect.pBot.x =  20; //      
  parRect.pBot.y = -10;
  parRect.pTop.x =  10; //     
  parRect.pTop.y =  10;
  //  1- ,     
  AddArrayItem( rArRect,             //   
                -1,                  //   
                &parRect,            //    
                sizeof( parRect ) ); //      

  parRect.pBot.x = 50; //      
  parRect.pBot.y = 10;  
  parRect.pTop.x = 20; //     
  parRect.pTop.y = 50;
  //  2- ,     
  AddArrayItem( rArRect,             //   
                -1,                  //   
                &parRect,            //    
                sizeof( parRect ) ); //      
  
  parRect.pTop.x = 20;  //      
  parRect.pTop.y = 150;
  parRect.pBot.x = 50;  //     
  parRect.pBot.y = 110;
  //  3- ,     
  AddArrayItem( rArRect,             //   
                -1,                  //   
                &parRect,            //    
                sizeof( parRect ) ); //      

  //      
  int count = GetArrayCount( rArRect );
  char buf[255];
  sprintf( buf, "count = %d", count );
  Message( buf );

  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArRect,             //   
                  i,                   //   
                  &parRect,            //    
                  sizeof( parRect ) ); //     
    sprintf( buf, "i = %d, pTop.x = %4.2f, pTop.y = %4.2f,\npBot.x = %4.2f, pBot.y = %4.2f", 
             i, parRect.pTop.x, parRect.pTop.y, parRect.pBot.x, parRect.pBot.y );
    Message( buf );
  }
  
  //    
  parRect.pBot.x =  10; //       
  parRect.pBot.y = -20;
  parRect.pTop.x =  0;  //     
  parRect.pTop.y =  0;  
  //   1-     
  SetArrayItem( rArRect,             //   
                0,                   //   
                &parRect,            //    
                sizeof( parRect ) ); //     
  
  parRect.pBot.x =  20; //      
  parRect.pBot.y = -10;
  parRect.pTop.x = -20; //     
  parRect.pTop.y = -50;  
  //   2-     
  SetArrayItem( rArRect,             //   
                1,                   //   
                &parRect,            //    
                sizeof( parRect ) ); //     

  parRect.pBot.x = 25; //      
  parRect.pBot.y = 0;
  parRect.pTop.x = 5;  //     
  parRect.pTop.y = 5;  
  //  4- ,     
  AddArrayItem( rArRect,             //   
                -1,                  //   
                &parRect,            //    
                sizeof( parRect ) ); //      

  //      
  count = GetArrayCount( rArRect );

  //    
  for ( int i = 0; i < count; i++ )
  {
    //    
    GetArrayItem( rArRect,             //   
                  i,                   //   
                  &parRect,            //    
                  sizeof( parRect ) ); //     
    sprintf( buf, "i = %d, pTop.x = %4.2f, pTop.y = %4.2f,\npBot.x = %4.2f, pBot.y = %4.2f", 
             i, parRect.pTop.x, parRect.pTop.y, parRect.pBot.x, parRect.pBot.y );
    Message( buf );
  }

  //     
  DeleteArray( rArRect );
}