xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

ValToPrg()

Converts a value to PRG code.

Syntax

ValToPrg( <xValue> ) --> cPRGcode

Arguments

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

Return

The function returns a character string that can be compiled as PRG code.

Description

Function ValToPrg() accepts a value of any data type and returns a character string holding PRG code. The PRG code can be compiled and produces the passed value. 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 compile to a pointer but to a Numeric value. Pointers are only determined at runtime of an application and cannot be hard coded.

Info

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

Example

// The example demonstrates return values of function ValToPrg()
// with data types where the function is guaranteed to work.

   PROCEDURE Main
      LOCAL aArray   := { 1, 2, 3 }
      LOCAL cString  := "xHarbour"
      LOCAL dDate    := Date()
      LOCAL hHash    := { "A" => 1, "B" => 2 }
      LOCAL lLogic   := .T.
      LOCAL nNumber  := 1.2345
      LOCAL pPointer := ( @Main() )
      LOCAL undef    := NIL

      ? ValToPrg( aArray   )    // result: {  1,  2,  3 }
      ? ValToPrg( cString  )    // result: "xHarbour"
      ? ValToPrg( dDate    )    // result: sToD( '20061011' )
      ? ValToPrg( hHash    )    // result: { "A" =>  1, "B" =>  2 }
      ? ValToPrg( lLogic   )    // result: .T.
      ? ValToPrg( nNumber  )    // result:          1.2345
      ? ValToPrg( pPointer )    // result: 0x4C5000
      ? ValToPrg( undef    )    // result: NIL
   RETURN

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