KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Reading an entire system document with one call to RECEIVE PACKET
PRODUCT: 4D | VERSION: 11.6 | PLATFORM: Mac & Win
Published On: April 16, 2010

As a technique for reading the entire contents of a document into a text variable a common construct has been:

RECEIVE PACKET($TimeRef_H;$MyTextVar_T;32000)


This is because in the history of 4D, 32,000 was the maximum size of a 4D text variable and would work with all file sizes under 32,000.

In 4D v11 SQL the maximum size of text variables has grown to 2GB. Because of this a more accurate way in 4D v11 SQL of reading the exact size of the document into a text variable is shown below:

C_TEXT($MyText_T)
$TimeRef_H:=Open document("")
If(OK=1)
   RECEIVE PACKET($TimeRef_H;$MyText_T;Document size(Document))
   CLOSE DOCUMENT($TimeRef_H)
End if


As constructed the code above will fail and files in 4D v11 SQL on a file greater than 2GB. If you have the potential for reading files with a size greater than 2GB you should add and perform a defensive test on the document size before reading in the file.

Commented by Cannon Smith on April 17, 2010 at 3:34 PM
Of course, "Document size" in the code should be "Get document size".