Printing from a TMemo

This should not be difficult but I am a bit retsricted on time at the moment so if someone can help me I would appreciate it tremendously. Hehe I used to have code doing this but have lost it with a drive crash. If someone has sample code for delphi 4 to print from a TMemo to a default printer, I will be very happy.
skymagAsked:
Who is Participating?
 
TheNeilConnect With a Mentor Commented:
Yeah I did. This wasn't cut and paste code it was typed straight in which explains why I missed it. At least you spotted it before using it

The Neil
0
 
TheNeilCommented:
Printer.BeginDoc;
Printer.Canvas.Font := Memo1.Font;

LineCount := 0;
LineHeight := Printer.Canvas.TextHeight('Aj');
FOR n := 0 TO Memo1.Lines.Count
DO
BEGIN
  Printer.TextOut(0, LineCount * LineHeight, Memo1.Lines[n]);
  LineCount := LineCount + 1;
  IF (LineCount * LineHeight) > Printer.PageHeight
  THEN
  BEGIN
    Printer.NewPage;
    LineCount := 0;
  END;
END;

Printer.EndDoc;

That'll do the job (assuming that you've got word wrap enabled on your Memo component)

The Neil
0
 
PeterLarsenCommented:
I think you ment "Printer.Canvas.TextOut". :-)
0
 
skymagAuthor Commented:
Thanx very much!

One small error:
Printer.TextOut(0, LineCount * LineHeight, Memo1.Lines[n]);
Should be:
Printer.Canvas.TextOut(0, LineCount * LineHeight, Memo1.Lines[n]);
 
0
All Courses

From novice to tech pro — start learning today.