Club 4D de Montréal

     

 

Accueil

Qu'est-ce que 4D?

Développeurs

Adresses des membres

Archives

Photographies

Site officiel de 4D

 

Subject: RE: VARIABLE TO BLOB
From: "Francois Marchal" <fmarchal@aci.fr>
Date: 8 Aug 1997 11:43:56 +0200

Hello,

VARIABLE TO BLOB accepts only two syntaxes (doc is false):
VARIABLE TO BLOB( var; blob )
the blob will be resized to hold only the variable
VARIABLE TO BLOB( var; blob; * )
the variable will be added at the end of the blob

The normal use of these commands to store in a blob
some variables together is:

1/ storing variables
-----------------------
VARIABLE TO BLOB( var1; blob )
VARIABLE TO BLOB( var2; blob; * )
VARIABLE TO BLOB( var3; blob; * )

2/ reading variables
-------------------------
offset := 0
BLOB TO VARIABLE( blob; var1; offset )
BLOB TO VARIABLE( blob; var2; offset )
BLOB TO VARIABLE( blob; var3; offset )

This is easy, and covers 99% of the case.
You just need to read variable in the same order than you store them.

If you want now to have a random access to the variables, you need to store also the offsets of the variables in the blobs. You can do it this way.

1/ storing
----------------------
a) storing variables, and store positions in an array
offsetOfVar{1} := 0
VARIABLE TO BLOB( var1; blob )
offsetOfVar{2} := BLOB size( blob )
VARIABLE TO BLOB( var2; blob; * )
offsetOfVar{3} := BLOB size( blob )
VARIABLE TO BLOB( var3; blob; * )

b) storing the array at the end of the blob
PositionOfArray := BLOB size( blob )
VARIABLE TO BLOB( offsetOfVar; blob; * )

c) storing position of the array at the end of the blob
LONGINT TO BLOB( PositionOfArray; blob; 0; * )

2/ reading
----------------------
a) reading position of the array at the end of the blob
offset = BLOB size( blob ) - 4
PositionOfArray := BLOB to longint( blob; 0; offset )

b) reading offset array
offset := PositionOfArray
BLOB TO VARIABLE( blob; offsetOfVar; offset )

c) now you can read any var in random order eg : reading var3
offset:=3DoffsetOfVar{3}
BLOB TO VARIABLE( blob; var3; offset )

Hope it helps,

- François Marchal (ACI) -