[fpc-pascal] Creating text files with TFileStream

Vincent Snijders vsnijders at vodafonevast.nl
Fri Oct 23 12:33:13 CEST 2009


Graeme Geldenhuys schreef:
> 2009/10/23 Vincent Snijders <vsnijders at vodafonevast.nl>:
>> Otherwise you cannot read it back. :-)
> 
> But using .WriteAnsiString() doesn't create a plain text file, so the
> result is useless. And as my last post says, the method Gerard
> suggested is also not 100%.
> 
> 
> It seems extra hard to create a normal, plain, standard text file with
> the TFileStream class.  This should had this puzzle to a "Programming
> Olympiad" - it's tougher than one thinks.
> 
> Anyway, so now I'm back to square one - unable to create a plain text
> file with TFileStream. :-(
> 
> 

You want easy?

Then use

var
   outfile: text;
begin
   rewrite(outfile)';
   writeln(outfile, 'Line 1');
   writeln;
   writeln(outfile, 'Line 3');

But you want streams?

procedure WriteSomeText(S: TStream);
var
   Lines: TStrings;
begin
   Lines := TStringList.Create;
   Lines.Add('Line 1');
   Lines.Add();
   Lines.Add('Line 3');
   Lines.SaveToStream(s);
   Lines.Free;
end;

Vincent




More information about the fpc-pascal mailing list