xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

ValToPrgExp()

Converts a value to a character string holding a macro-expression.

Syntax

ValToPrgExp( <xValue> ) --> cMacroExpression

Arguments

<xValue>
This is a value of any data type.

Return

The function returns a character string that can be compiled with the macro operator.

Description

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.

Info

See also:&, CStr(), HB_Serialize(), PrgExpToVal(), Valtype(), ValToPrg()
Category: Conversion functions , xHarbour extensions
Source:rtl\cstr.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe