What if you have to write a banking interface for Navision, where a line in the text file can easily more than 1024 chars long?
1) You cannot write one variable for a line, as a text var can only be 1024 chars long.
2) You cannot write in binary mode, as Navision will insert zero bytes after strings.
3) You could try to concatenate two or more text variables when writing, but even if it works, that's an ugly hack and it is hard to build a general "interface framework" on top of it.
The right solution is OUTSTREAM.
variables:
CR: char
LF: char
CRLF : text(2)
ThisFile: file
Stream: OutStream
CR:=13;
LF:=10;
CRLF:=format(CR)+format(LF);
ThisFIle.TEXTMODE(FALSE);
ThisFile.CREATE('c:\dammit.txt');
ThisFile.CREATEOUTSTREAM(Stream);
Stream.WRITETEXT('Ha!');
Stream.WRITETEXT('No zeroes, no spaces, no newlines, no problem!');
Stream.WRITETEXT(CRLF);
Stream.WRITETEXT('See?');
ThisFile.CLOSE;
Comments
Fil.WRITE(COPYSTR(txtMyString,1,STRLEN(txtMyString)); // the COPYSTR is needed, because otherwise the full length of txtMyString is written.
fil.SEEK(fil.POS - 1); // this repositions on the zero-byte and will be overwritten by the next WRITE.
Also the CRLF you made, I used.
So, now also the poor guys that are still working with older Navision-versions can write longer strings.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Do It Yourself is they key. Standard code might work - your code surely works.
I did something like this when no streams existed and it worked.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!