To retrieve a variable stored in a BLOB, it destination variable must be of the same type as the variable stored in the BLOB. The command BLOB TO VARIABLE will not "coerce" a variable from one type to another, such as converting a Long Integer to Text.
So, if it is not possible to know before hand what type of variable is stored in the BLOB, programmatically determining the variable type becomes important before using the BLOB TO VARIABLE command. Below are two methods that used together will return the type of variable stored in a BLOB.
For a variable stored in a BLOB, the variable type is stored in the 5the byte of the BLOB (offset #5). Not all varaibles can be stored in a BLOB. The list below is a list of the type of variuables that can be stored in a BLOB.
Value Type
0 Alpha variable
1 Number
2 Text
3 Picture
4 Date
5 Undefined variable
6 Boolean
7 Subtable
8 Integer
9 Long integer
11 Time
14 Number array
15 Integer array
16 Longint array
17 Date array
18 Text array
19 Picture array
21 String array
22 Boolean array
23 Is a pointer
24 String variable
30 BLOB
Some values must be realigned for UNICODE applications:
33 means UNICODE Text
10 means Picture
The method below, GetBLOBedVarType, returns the variable type stored in a BLOB at the specified offset.
If (True) If (False) //***************************************************************************** // // GetBLOBedVarType ( ->$BLOB_P {; $Offset_L } ) -> Longint // // Purpose: Return the type of varaible stored in a BLOB // Accounts for the new variables types in a UNICODE application // // $0 - long, type of variable in the BLOB // $1 - pointer to blob // $2 - long, offset in the blob (optionnal) // // //***************************************************************************** End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //===================== Declare Variables ================================== //method_parameters_declarations C_LONGINT($0) class="TT4DCommand">C_POINTER($1;$BLOB_P) C_LONGINT($2;$Offset_L) //-------------------------------------------------------------------------------- End if //====================== Initialize and Setup ================================ $0:=Is Undefined $BLOB_P:=$1 If (Count parameters>1) $Offset_L:=$2 Else $Offset_L:=0 End if //======================== Method Actions ================================== If (IsBLOBedVar ($BLOB_P;$Offset_L)) // Kind is in the 5th byte (offest #4) // $0:=$BLOB_P->{$Offset_L+4} //======================== Clean up and Exit ================================= // Realign of values in v11 and v12 UNICODE applications // Case of : ($0=33) $0:=Is Text : ($0=10) $0:=Is Picture End case End if |
The method below, IsBLOBedVar, returns true if the BLOB has a signature of "RVLB" or "BLVR".
If (True) If (False) //***************************************************************************** // // IsBLOBedVar ( ->$BLOB_P ) -> Boolean // // Purpose: IsBLOBedVar checks the 4 first bytes for BLVR or RVLB // NOTE: Should be always RVLB with Intel CPUs (BLVR for old PPC Macs) // // $1 - Pointer - Pointer to the BLOB // //***************************************************************************** End if C_TEXT($MethodName_T) $MethodName_T:=Current method name //===================== Declare Variables ================================== //method_parameters_declarations C_BOOLEAN($0) C_POINTER($1;$BLOB_P) //-------------------------------------------------------------------------------- //method_wide_constants_declarations //-------------------------------------------------------------------------------- //local_variable_declarations C_TEXT($Tag_T) End if //====================== Initialize and Setup ================================ $BLOB_P:=$1 //======================== Method Actions ================================== $Tag_T:=Char($BLOB_P->{0})\ +Char($BLOB_P->{1})\ +Char($BLOB_P->{2})\ +Char($BLOB_P->{3}) //======================== Clean up and Exit ================================= $0:=(($Tag_T="BLVR") | ($Tag_T="RVLB")) |