Tech Tip: Utility method to Convert Data to a Text Type
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Win
Published On: February 27, 2015
Below is a method to convert most data types to a text form allowing for more flexibility in ways to handle data:
// Method: Convert_To_Text // Description: // Converts input to Text returns the result // // Parameters: // $1 - Pointer to the data that will be converted to text // // $0 - Returns input in text form for most datatypes // Blobs and pictures are returned in BASE64 ENCODED text //----------------------------------------------------- C_POINTER($1;$input_ptr) C_TEXT($0) C_LONGINT($type_l) C_BLOB($picture_b) If(Count parameters=1) $input_ptr:=$1 $type_l:=Type($input_ptr->) Case of : ($type_l=Is text) | ($type_l=Is string var) | ($type_l=Is alpha field) $0:=$input_ptr-> : ($type_l=Is integer) | ($type_l=Is longint) | ($type_l=Is real) | ($type_l=Is float) $0:=String($input_ptr->) : ($type_l=Is time) $0:=String($input_ptr->) : ($type_l=Is Boolean) $0:=String($input_ptr->) : ($type_l=Is date) $0:=String($input_ptr->) : ($type_l=Is BLOB) BASE64 ENCODE($input_ptr->;$0) : ($type_l=Is picture) PICTURE TO BLOB($input_ptr->;$picture_b;".png") BASE64 ENCODE($picture_b;$0) Else $0:="" End case End if |