The code examples in this topic demonstrate how you can read
from and write to streams. These examples require the following
variables.
Variable name |
Data type |
Subtype |
recEmployee
|
Record
|
Employee
|
XMLDom
|
Automation
|
XMLDomDoc
|
StreamOutObj
|
OutStream
|
|
StreamInObj
|
InStream
|
|
Txt
|
Text
|
|
Buffer
|
Text
|
|
CreationDate
|
Date
|
|
Writing Data to an OutStream
The following code example creates an OutStream to stream data
out of a BLOB field for storage in an external object.
|
Copy Code |
// Define the record number.
recEmployee."No." := '5555';
// Load the XML DOM, which will pass the OutStream to the
// external object.
XMLDom.load('SomeData.xml');
recEmployee.Picture.CREATEOUTSTREAM(StreamOutObj);
StreamOutObj.WRITE('Ver. 1.00');
// Write version.
StreamOutObj.WRITE('Company Ltd.');
// Write (c).
StreamOutObj.WRITE(TODAY);
// Write a DATE (today).
// The following information will be written as plain text.
StreamOutObj.WRITETEXT('Dear Customer,');
StreamOutObj.WRITETEXT();
// This inserts a carriage return and a new line.
StreamOutObj.WRITETEXT('We would like to thank you for your help.');
StreamOutObj.WRITETEXT();
StreamOutObj.WRITETEXT('We hope to see you soon!');
StreamOutObj.WRITETEXT();
XMLDom.save(StreamOutObj);
recEmployee.MODIFY();
|
Reading Data from an InStream
The following code creates an InStream to stream data into a
BLOB field. This example requires that you create the following
text constants in the C/AL Globals window.
Text constant |
ENU value |
Text000
|
'Version is: %1'
|
Text001
|
'Copyright %1'
|
Text002
|
'Creation Date: %1'
|
|
Copy Code |
recEmployee.Picture.CREATEINSTREAM(StreamInObj);
// Read version.
StreamInObj.READ(Txt);
MESSAGE(Text000, Txt);
// Read (c).
StreamInObj.READ(Txt);
MESSAGE(Text001, Txt);
// Read date.
StreamInObj.READ(CreationDate);
MESSAGE(Text002, CreationDate);
StreamInObj.READTEXT(Buffer);
Message(Buffer);
StreamInObj.READTEXT(Buffer);
Message(Buffer);
StreamInObj.READTEXT(Buffer);
Message(Buffer);
XMLDom.load(StreamInObj);
|
See Also