Archive for the ‘Text File’ Category

How to create a text file and Write/Append text into the file

Sunday, September 11th, 2011

// TextFile is File object
// OutStreamObj is OutStream object
// CR and LF are Char trype

TextFile.CREATE( ‘C:\TextOutput.txt’); // To Create
TextFile.CREATEOUTSTREAM(OutStreamObj);

OutStreamObj.WRITETEXT (’1st Line’); // To write into the created text file

OutStreamObj.WRITETEXT (’This is not the second line of text to be outputed but to concatenate with the first line’);

OutStreamObj.WRITETEXT(); // This command is to move to next line
OutStreamObj.WRITETEXT(’2nd Line’) ;

TextFile.Close; // To end the writing and write out to the file.

// To Append text at the end of text file

TextFile.TEXTMODE := TRUE;

TextFile.WRITEMODE := TRUE;

TextFile.OPEN(’C:\TextOutput.txt’);

TextFile.SEEK(TextFile.LEN);

TextFile.WRITE(’2nd Line end’);

TextFile.CLOSE;

 // To Append text in new line of text file

CR := 10;

LF := 13;

TextFile.TEXTMODE := TRUE;

TextFile.WRITEMODE := TRUE;

TextFile.OPEN(’C:\TextOutput.txt’);

TextFile.SEEK(TextFile.LEN);

TextFile.WRITE(CR);

//OR

TextFile.WRITE(LF);

TextFile.WRITE(’3rd Line’);

TextFile.CLOSE;