program Project1;
{$mode objfpc}{$H+}
uses
StreamIO,
Classes;
var
sl: TStringList;
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
try
// Redirect output to MS
AssignStream(Output, ms);
Rewrite(Output);
// This should now land in MS
WriteLn('Hello Stream');
// Read out MS into a string list
sl := TStringList.Create;
try
ms.Seek(0, soBeginning);
sl.LoadFromStream(ms);
// Check whats in SL:
// Print on ErrOut (because Output is redirected to MS)
WriteLn(ErrOutput, 'SL.Text: ', sl.Text);
finally
sl.Free;
end;
finally
ms.Free;
end;
end.