Function Bin2Var() Foundation

Converts the return value of Var2Bin() back to the original value.

Syntax
Bin2Var( <cBinaryString> ) --> xValue
Parameters
<cBinaryString>
<cBinaryString> is a character string containing the binary representation of a value. It is being created by the function Var2Bin().
Return

The function Bin2Var() returns the original value previously converted to a binary string by Var2Bin().

Description

Bin2Var() is the inverse function of Var2Bin(). A binary character string created by Var2Bin() is converted back to the original value with Bin2Var().

Conversion of objects

When objects are converted with Bin2Var(), the method :notifyLoaded()is automatically executed if it is declared in the corresponding class. This allows for taking appropriate action if an object has non-persistent instance variables (VAR...NOSAVE).

Examples
Converting persistent objects

// The example demonstrates how objects are notified when they are 
// converted from binary representation to the original data type. 
// The method :notifyLoaded() is implemented in the class MyClass 
// and executed after Bin2Var(). 

#include "Common.ch" 

PROCEDURE MAIN 
   LOCAL cString := "Object 1" 
   LOCAL aArray  := {"Hello", "World"} 
   LOCAL obj1, obj2 

   obj1 := MyClass():new( cString ) 
   obj2 := MyClass():new( aArray ) 

   ? "Objects are created" 

   obj1:show() 
   obj2:show() 

   WAIT "About to convert objects, press a key" 

   ? Valtype( obj1 ) + Valtype( obj2 )  // Result: "OO" 

   obj1 := Var2Bin( obj1 ) 
   obj2 := Var2Bin( obj2 ) 

   ? Valtype( obj1 ) + Valtype( obj2 )  // Result: "CC" 

   WAIT "About to convert back, press a key" 

   obj1 := Bin2Var( obj1 ) 
   obj2 := Bin2Var( obj2 ) 

   WAIT 
RETURN 


************ 
CLASS MyClass 
   EXPORTED: 
   VAR iVar 

   INLINE METHOD init( xValue ) 
      DEFAULT xValue TO ::className() 
      ::iVar := xValue 
   RETURN self 

   INLINE METHOD notifyLoaded 
      ? "I am restored:", ::iVar 
   RETURN self 

   INLINE METHOD show 
      ? ::iVar 
   RETURN self 
ENDCLASS 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.