KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Concatenating system documents together
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: December 15, 2000

Suppose you have two or more system documents (files) that you wish to combine into one, larger document - you can do so with the help of BLOBs. The basic idea is to load the content of the second and subsequent documents into a BLOB one at a time, then convert the BLOB contents into a text variable that can then be passed to SEND PACKET. Once we have the contents of a document stored in a text variable ($str), we can append it onto the initial document repeating as necessary for each additional file.
The follow codes illustrate how to append DocumentA.txt onto DocumentB.txt (concatenating B and A). Note that this code can only handle documents up to 32K in size due to the limitation of text variables in 4D. Larger documents would need to be handled in chunks of 32K or smaller.

Copy and paste the following code into your 4D project:
C_TIME($DocRef1)
C_TEXT($str)
C_BLOB(blb)

DOCUMENT TO BLOB("DocumentA.txt";blb)
vOffSet:=0
$str:=BLOB to text(blb;0;vOffSet)

$DocRef1:=Append document("DocumentB";"TXT")
SEND PACKET($DocRef1;$str)
CLOSE DOCUMENT($DocRef1)