Printer4Lazarus not working lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- asmx · 2024-01-07 12:11 I followed this page (https://wiki.freepascal.org/Using_the_printer) to write a print test program, but it doesn't work properly. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program PrintUtil; uses  SysUtils, printers; const  LEFTMARGIN = 100;  HEADLINE = 'I Printed My Very First Text On ';var  YPos, LineHeight, VerticalMargin: integer;  SuccessString: string;begin  with Printer do  try    BeginDoc;    Canvas.Font.Name := 'Courier New';    Canvas.Font.Size := 10;    Canvas.Font.Color := $0;    LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));    VerticalMargin := 4 * LineHeight;    // There we go    YPos := VerticalMargin;    SuccessString := HEADLINE + DateTimeToStr(Now);    Canvas.TextOut(LEFTMARGIN, YPos, SuccessString);  finally    EndDoc;  end; end.  AccessViolationException is thrown directly when running to BeginDoc. ---------------------------------------------------------------------- wp · 2024-01-07 15:48 The wiki article you are referring to is meant for printing out of a Lazarus GUI application. You are testing printing, however, in a console application. The difference is that a console application by- passes the Lazarus widgetset architecture and does not know about the LCL. The elemental step to make the LCL available in a consolue application is to add the unit "Interfaces" to the uses clause. But then you need another unit: "OSPrinters" to make the printer units of your operating system available. So, in total, modify your uses clause as follows, and your application will work (tested on Windows): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program PrintUtil; uses  Interfaces,    // <--- ADDED  SysUtils, printers,  osprinters;    // <--- ADDED  //, printer4lazarus;          // <--- Not needed in "uses", but only in "required packages" of project const  LEFTMARGIN = 100;  HEADLINE = 'I Printed My Very First Text On ';var  YPos, LineHeight, VerticalMargin: integer;  SuccessString: string;begin  with Printer do  try    BeginDoc;    Canvas.Font.Name := 'Courier New';    Canvas.Font.Size := 10;    Canvas.Font.Color := $0;    LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));    VerticalMargin := 4 * LineHeight;    // There we go    YPos := VerticalMargin;    SuccessString := HEADLINE + DateTimeToStr(Now);    Canvas.TextOut(LEFTMARGIN, YPos, SuccessString);  finally    EndDoc;  end; end. ---------------------------------------------------------------------- AlexTP · 2024-01-07 17:20 I added this new info (for me) to wiki: https://wiki.freepascal.org/Using_the_printer#Printing_from_console_ap plication ---------------------------------------------------------------------- Thaddy · 2024-01-07 18:10 If you want simple printing from a console app, use the unit printer, not printers. It is limited to what was possible in DOS times, but does the job. ---------------------------------------------------------------------- asmx · 2024-01-08 13:07 Quote from: wp on January 07, 2024, 04:48:19 pmThe wiki article you are referring to is meant for printing out of a Lazarus GUI application. You are testing printing, however, in a console application. The difference is that a console application by-passes the Lazarus widgetset architecture and does not know about the LCL. The elemental step to make the LCL available in a consolue application is to add the unit "Interfaces" to the uses clause. But then you need another unit: "OSPrinters" to make the printer units of your operating system available. So, in total, modify your uses clause as follows, and your application will work (tested on Windows): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program PrintUtil; uses  Interfaces,    // <--- ADDED  SysUtils, printers,  osprinters;    // <--- ADDED  //, printer4lazarus;          // <--- Not needed in "uses", but only in "required packages" of project const  LEFTMARGIN = 100;  HEADLINE = 'I Printed My Very First Text On ';var  YPos, LineHeight, VerticalMargin: integer;  SuccessString: string;begin  with Printer do  try    BeginDoc;    Canvas.Font.Name := 'Courier New';    Canvas.Font.Size := 10;    Canvas.Font.Color := $0;    LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));    VerticalMargin := 4 * LineHeight;    // There we go    YPos := VerticalMargin;    SuccessString := HEADLINE + DateTimeToStr(Now);    Canvas.TextOut(LEFTMARGIN, YPos, SuccessString);  finally    EndDoc;  end; end. Thank you for reply , It worked! ---------------------------------------------------------------------- asmx · 2024-01-08 14:59 Thanks every one!