Hi Gurus,
I have a BLOB field where i am importing a txt file;
Next i have to create append mechansim that is when i select any other file, the system should not overwrite my existing data found BLOB field but it should append it.
Any quick trick to get this thing done apart from reading the blob field, createinstream and then read the data and thn put it somwhere.
I have done this copy stream trick but this isint working. Any trick or help
This code is called at the IMPORT button on Form:
Rec.CALCFIELDS(Comments);
IF Rec.Comments.HASVALUE THEN BEGIN
RMCommentLine.Comments.IMPORT('*.txt',TRUE);
RMCommentLine.Comments.CREATEINSTREAM(StreamInObj);
Rec.Comments.CREATEOUTSTREAM(StreamOutObj);
COPYSTREAM(StreamOutObj,StreamInObj);
CurrForm.UPDATE;
END
ELSE BEGIN
Rec.Comments.IMPORT('*.txt',TRUE);
CurrForm.UPDATE;
END;
Answers
You'll have to export the contents of the BLOB-field to a file on disk, append the new data to this file and finally import this new file into the BLOB-field and thus overwriting the old data.
1.) save the BLOB in on ther BLOB field (COYPSTREAM)
2.) clear the original BLOB field
3.) use a INSTREAM from the tempBLOB and wriite to the original field with WRITE
4.) once INSTREAM (tempBLOB) is EOS, read from INSTREAM containing the data to append and use the same OUTSTREAM to write the data
COPYSTREAM always seeks to position 0 within the OUTSTREAM. As you can not move the stream pointer, you can not simply use COPYSTREAM to append.
MCP+I, MCSE NT, Navision MCT (2004,2005)
Yeah this thing can be done in 2 ways;
a) either through exporting the files and merging them through Shell command
b) Manipulation with streams.
I have selected option b) and its working fine here at my end.
Here is the code so that it can be useful for everybody:
The code is written on the IMPORT button of form: