Forum > Beginners

<Solved>Easy printing TMemo in my case Memo1.Lines

<< < (2/2)

Sprek Skik:

--- Quote from: dbannon on May 20, 2024, 01:53:37 am ---I always set the printerfont  colour and size, they probably have sensible defaults but maybe not ? eg

Anyway, as Jamie said, you need to check the content, 'Line' should increase with each loop (But MUST be reset when you start a new page by the way).  To make it easy to debug, you might like to add a line or two -

A bit easier for a beginner, set the debugger up to stop on the line AFTER "AString ;= " line, click on that line, then click in the 'left gutter' (the area to the left, where line number appear). That will set a red background under that line meaning the debugger will stop there.

A new project will have debugging turned on, so, now just click 'run', your app will startup, get as far as that line and stop, waiting for you to reclick the green 'run' triangle.  While its in that waiting mode, hover your mouse over variables of interest and you will see their current value. You can step through, line by line with eg F8


--- End quote ---
Thanks for the reply!  I made the changes with the setup of printer. It made the difference a small text file is ok, but with a larger file the program makes  a lot of empty pages.

I think you are right with resetting Line, but what code should I add to make this work? Thanks for the extra info about debugging it is all new for me.

Sprek Skik:
Well I have solved it!

The code;

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfrmPrinterSetUp.PrintMemo;var  I,  Line : Integer;  begin  I := 0;  Line := 0 ;  Printer.BeginDoc ;  Printer.Canvas.Font.Name := 'MS Sans Serif';  Printer.Canvas.Font.Size := 10;  Printer.Canvas.Font.Color := clBlack;  for I := 0 to Memo1.Lines.Count - 1 do begin    Printer.Canvas.TextOut(0, Line, Memo1.Lines[I]);     {Font.Height is calculated as -Font.Size * 72 / Font.PixelsPerInch which returns     a negative number. So Abs() is applied to the Height to make it a non-negative     value}    Line := Line + Abs(Printer.Canvas.Font.Height);    if (Line >= Printer.PageHeight) then      begin        Line := 0;        Printer.NewPage;      end;   end;  Printer.EndDoc;end; 


[0] Message Index

[*] Previous page

Go to full version