| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Converts a value to a character string holding a macro-expression.
ValToPrgExp( <xValue> ) --> cMacroExpression
The function returns a character string that can be compiled with the macro operator.
Function ValToPrgExp() accepts a value of any data type and returns a character string holding a macro-expression. This expression produces the value when it is compiled with the Macro-operator. This is guaranteed for all data types except Object and Code block, since certain restrictions exist for these data types when they are serialized into a character string. Refer to function HB_Serialize() for more information on these restrictions.
Note: if a pointer is passed, the produced PRG code is a Hex number which does not macro-compile to a pointer but to a Numeric value.
| See also: | &, CStr(), HB_Serialize(), PrgExpToVal(), Valtype(), ValToPrg() |
| Category: | Conversion functions , xHarbour extensions |
| Source: | rtl\cstr.prg |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates return values of function ValToPrgExp()
// with data types where the function is guaranteed to work.
PROCEDURE Main
LOCAL aArray := { 1, 2, 3 }
LOCAL cString := "xHb"
LOCAL dDate := Date()
LOCAL hHash := { "A" => 1, "B" => 2 }
LOCAL lLogic := .T.
LOCAL nNumber := 1.2345
LOCAL pPointer := ( @Main() )
LOCAL undef := NIL
? ValToPrgExp( aArray ) // result: { 1, 2, 3 }
? ValToPrgExp( cString ) // result: Chr(120) + Chr(72) + Chr(98)
? ValToPrgExp( dDate ) // result: sToD( '20061011' )
? ValToPrgExp( hHash ) // result: { Chr( 65) => 1, Chr( 66) => 2 }
? ValToPrgExp( lLogic ) // result: .T.
? ValToPrgExp( pPointer ) // result: HexToNum('4C5000')
? ValToPrgExp( undef ) // result: NIL
RETURN
http://www.xHarbour.com