I am using that code to print a memo, however if I have no printer installed, it errors, how can I trap the error? so that, it will not crash the program.
procedure PrintTStrings(Lst : TStrings) ;
var
I,
Line : Integer;
begin
I := 0;
Line := 0 ;
Printer.BeginDoc;
for I := 0 to Lst.Count - 1 do begin
Printer.Canvas.TextOut(0, Line, Lst);
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.PageHeight) then
Printer.NewPage;
end;
Printer.EndDoc;
end;
procedure TForm1.BTNprintClick(Sender: TObject);
begin
if Printer.Printers.Strings[-1]<>'' then
begin
try
PrintTStrings(Memo1.lines);
except
showmessage('NO printer');
end;
end;
end;
using that code because assignprn() is gone.