How I can insert a new …

How I can insert  a new item to an array ?

Short answer : We have a special function : AIns()
Long Answer :

AIns() function may cause some confusions when documentation not read carefully:

This function inserts a NIL value in the array named <aArray> at the <nPos>th position.

All array elements starting with the <nPos>th position will be shifted down one subscript position in the array list and the last item in the array will be removed completely.

 

Let’s try:

 aTest := { 'One', 'Two', 'Four' }
 AIns( aTest, 3 ) 
 AEVAL( aTest, { | c1 | QQOUT( c1, '' ) } ) 
 

Result : One Two NIL: “Four” lost !

Since it’s NIL, we can assign a value to it:

 aTest := { 'One', 'Two', 'Four' }
 AIns( aTest, 3 )
 aTest[ 3 ] := "Three"
 AEVAL( aTest, { | c1 | QQOUT( c1, '' ) } ) 
 

Result : One Two Three: “Four” lost !

Before insert we can add a dummy item to end of array:

 aTest := { 'One', 'Two', 'Four' }
 AADD( aTest, NIL )
 AIns( aTest, 3 )
 aTest[ 3 ] := "Three"
 AEVAL( aTest, { | c1 | QQOUT( c1, '' ) } ) 
 

Result : One Two Three Four : OK
Or we can change size of array :

 aTest := { 'One', 'Two', 'Four' }
 ASIZE( aTest, 4 )
 AIns( aTest, 3 )
 aTest[ 3 ] := "Three"
 AEVAL( aTest, { | c1 | QQOUT( c1, '' ) } ) 
 

Result : One Two Three Four : OK

But wait; we have another possibility: a new Harbour function:

 aTest := { 'One', 'Two', 'Four' }
 HB_AIns( aTest, 3, "Three" )
 AEVAL( aTest, { | c1 | QQOUT( c1, '' ) } ) 

Result : One Two Three: “Four” lost !

And we have a fourth parameter : Grow or not:

 aTest := { 'One', 'Two', 'Four' }
 HB_AIns( aTest, 3, "Three", .T. )
 AEVAL( aTest, { | c1 | QQOUT( c1, '' ) } ) 
 

Result : One Two Three Four

That’s all !

Introduction Set Status

Introduction

     In this chapter, the group of functions determine the switch status and
     were implemented in the Clipper Tools. Clipper implemented the SET() 
     function, so that these settings can be determined, set, and saved 
     with this version.
     Therefore, some functions in this chapter only exist to enable
     compatibility with existing programs.  All the affected functions are
     flagged with an "*".

     If the functions relate to the Clipper switches (SET's), the function
     name is represented as follows:  CSET + the first four characters of the
     switch name.  For example, if the switch is named CONFIRM, then the
     function that corresponds is CSETCONF().  If the parameter is optional
     and unspecified, the function returns the current setting for its
     switch, without a status change.  When called with parameters, the
     function sets the switch to the passed value and returns the prior
     status as a value.  In this way, a function call can both change a
     switch and save the old status.  The logical value .T. corresponds to
     the ON setting of a switch; .F. corresponds to OFF.

 Example

     In the following example, the CONFIRM switch was set to .F.:

     lOldValue:= CSETCONF(.T.)

     After execution, the old variable lOldValue has a value of .F.; while
     the CONFIRM switch is ON (.T.).

     In addition to their usefulness with Clipper switches, these
     functions determine an assortment of other status information.  For
     example, you can determine the current status of the debugger, set
     LASTKEY, and differentiate key traps.  You can also determine the status
     of CAPS-LOCK, NUM-LOCK, INSERT, and SCROLL-LOCK.

 

Note:

     Since this section is about DOS-TEXT mode programming, considered 
     as obsolete and details skipped.