KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: What to do if BLOB TO VARIABLE does not work in compiled mode
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: September 5, 2007

4d is, in general, very forgiving when it comes to typing (also called "declaring") variables.

However when using the VARIABLE TO BLOB and BLOB TO VARIABLE commands it is very important that your typing be specific.

When you turn a variable into a BLOB using the VARIABLE TO BLOB command, that variable has a certain type (even if you do not specify it). Thus when you try to retrieve that variable with the BLOB TO VARIABLE command you must make sure the type is the same.

Here is a bad example:

SELECTION TO ARRAY([Invoices]CustomerID;myArray)
VARIABLE TO BLOB(myArray;myBLOB)
[Table 2]SomeBLOBField:=myBLOB
SAVE RECORD([Table 2]SomeBLOBField)


Then, some place later in your code...

theSavedBLOB:=[Table 2]SomeBLOBField
BLOB TO VARIABLE(theSavedBlob;myNewArray)


This will result in a syntax error in compiled mode.

In this example what is the type of "myNewArray"? It's anyone's guess (or, in this case, 4D's guess). In this case 4D will probably set the type of "myNewArray" to a Real, which obviously will not work.

Here is the proper way to handle this:

ARRAY TEXT(myArray;0)
C_BLOB(myBlOB)

SELECTION TO ARRAY([Invoices]CustomerID;myArray)
VARIABLE TO BLOB(myArray;myBLOB)
[Table 2]SomeBLOBField:=myBLOB
SAVE RECORD([Table 2]SomeBLOBField)



Then, some place later in your code...

ARRAY TEXT(myNewArray;0)
C_BLOB(theSavedBLOB)

theSavedBLOB:=[Table 2]SomeBLOBField
BLOB TO VARIABLE(theSavedBlob;myNewArray)



In general it is always recommended to specify typing for every variable you use in your code but in this case it is required to do so.