Printing Delphi

Title: How to print the contents of a TMemo or TListbox?
Question: The function below accepts a TStrings object as a parameter and prints out each string to the default printer. Because it uses a TStrings, the function will work with any type of component that contains a TStrings-type property, such as a TDBMemo or TOutline.
Answer:
uses Printers;
procedure PrintStrings(Strings: TStrings);
var
Prn: TextFile;
i: word;
begin
AssignPrn(Prn);
try
Rewrite(Prn);
try
for i := 0 to Strings.Count - 1 do
writeln(Prn, Strings.Strings[i]);
finally
CloseFile(Prn);
end;
except
on EInOutError do
MessageDlg('Error Printing text.', mtError, [mbOk], 0);
end;
end;
You can use it like this:
PrintStrings(Memo1.Lines);
or
PrintStrings(Listbox1.Items);