I cannot seem to get the text of a TMemo to print. I can get it to print, but it prints 3 of the same pages. Also, how would I calculate the totalPages so that the procedure knows when to stop printing? I am not supposed to use any 3rd party components.
Here is my code
function PrintPage(sText:string):boolean;
var
DestRect:TRectF;
align:TTextAlign;
textFill: tFillTextFlags;
printDialog: TPrintDialog;
totalPages : integer;
begin
printDialog := TPrintDialog.Create(nil);
printDialog.PrintRange := TPrintRange.prAllPages;
textFill := [];
align:=TTextAlign.taLeading;
totalPages := 3;
if printDialog.Execute() Then
begin
with Printer do
begin
ActivePrinter;
BeginDoc;
while Printer.Printing do
begin
DestRect := RectF(50,50,(Printer.Pagewidth – 50),(Printer.PageHeight – 50));
Canvas.FillText(DestRect,sText,True,1,textFill,align,align);
if Printer.PageNumber <> totalPages then
Printer.NewPage
else
EndDoc;
end;
end;
Result := not Printer.Aborted;
end;
end;