Since Clipper 5, is high reccomended to avoid use of Memvar ( Public and Private ): it's over 20 year ago !!!
But frequently I see code fragments using this poor habit ( if it work's then I dont care about nothing )
May be some user's dont know what to do for this case, for this peoples I create the below samples.
Case 1: Replace a Public Array ( Like in HMG: _HMG_SYSDATA )
Code: Select all
// *---------------------------------------------------------------------------*
// MR_Set_Arr( n_aElement__, e_Value__ )
// *---------------------------------------------------------------------------*
FUNCTION MR_Set_Arr( n_aElement__, e_Value__ )
LOCAL xAux
STATIC aAux := {}
IF ( Len( aAux ) < n_aElement__ )
ASize( aAux, n_aElement__ )
ENDIF
xAux := aAux[ n_aElement__ ]
IF PCount() > 1
IF HB_ISARRAY( e_Value__ )
aAux[ n_aElement__ ] := AClone( e_Value__ )
ELSE
aAux[ n_aElement__ ] := e_Value__
ENDIF
ENDIF
RETURN( xAux )
Code: Select all
LOCAL xAux
MR_Set_Arr( 1 'Hello Word !' )
MR_Set_Arr( 2, 'This is soo easy :)' )
MR_Set_Arr( 3, date() )
xAux := MR_Set_Arr( 1 ) + hb_eol()
xAux += MR_Set_Arr( 2 )
xAux += DTOS( MR_Set_Arr( 3 ) )
MSGINFO( xAux, xAux )
Code: Select all
// *---------------------------------------------------------------------------*
// MR_Set_Hash( c_hElement__, e_Value__ )
// *---------------------------------------------------------------------------*
FUNCTION MR_Set_Hash( c_hElement__, e_Value__ )
LOCAL xAux
STATIC hAux := { => }
IF PCount() > 1
IF HB_ISARRAY( e_Value__ )
hAux[ c_hElement__ ] := AClone( e_Value__ )
ELSE
hAux[ c_hElement__ ] := e_Value__
ENDIF
ELSE
xAux := hAux[ c_hElement__ ]
ENDIF
RETURN( xAux )
Code: Select all
LOCAL xAux
MR_Set_Hash( 'any_string', 'Hello Word !' )
MR_Set_Hash( 'new_element', 'This is soo easy :)' )
MR_Set_Hash( 'date_element', date() )
xAux := MR_Set_Hash( 'any_string' ) + hb_eol()
xAux += MR_Set_Hash( 'new_element' )
xAux += dtos( MR_Set_Hash( 'date_element' ) )
MSGINFO( xAux, xAux )
Internally - Clipper/Harbour use this technique intensively, like:
setkey( ..., ... )
set( ..., ... )
hb_gtInfo( ..., ... )
...
Feel free to ask any thing about this treat
Regards