local procedure ReadAttachments(var InS: InStream; DocumentRef: RecordRef; iTableNo: Integer; txtNoFieldName: Text): Boolean
var
recDA: Record "Document Attachment";
fldRef: FieldRef;
iNoFieldNo: Integer;
txtNoValue: Text;
OutS: OutStream;
TempBlobAtt: Codeunit "Temp Blob";
Buffer: array[1024] of Byte;
ReadBytes: Integer;
bReturnValue: Boolean;
begin
bReturnValue := false;
Clear(InS);
// initialise OutS
TempBlobAtt.CreateOutStream(OutS, TextEncoding::Windows);
iNoFieldNo := GetFieldNumber(txtNoFieldName, iTableNo);
recDA.SetFilter("Table ID", Format(iTableNo));
fldRef := DocumentRef.Field(iNoFieldNo);
txtNoValue := fldRef.Value;
recDA.SetFilter("No.", txtNoValue);
if recDA.FindSet() then begin
bReturnValue := true;
repeat
// Create OutStream from "Document Attachment" object.
// In other words, export the bytes of the "Document Attachment" database field into the OutStream.
recDA."Document Reference ID".ExportStream(OutS);
// Tie InS (InStream) to OutS (OutStream) via TempBlob object
TempBlobAtt.CreateInStream(InS, TextEncoding::Windows);
// *** This line is erroring ***
OutS.Write(InS);
// *****************************
until recDA.Next() = 0;
// Now OutS contains data from all attachments
// Create InStream from the same TempBlob
// Clear(InS);
TempBlobAtt.CreateInStream(Ins);
// Now Ins contains the concatenated data
end;
end;