Setting PaperName Causes Error - How To handle? lazarus / 31-LCL ---------------------------------------------------------------------- Dan3468298 · 2020-07-24 01:17 I have two Brother printers and Dymo LabelWriter 450.   The Brother printers support DefaultPaperName but the Dymo does not.   I used Try to catch the error of the Dymo not having a US Letter paper size but this doesn't work.   This error happens when changing the printer from one of the Brothers to the Demo and Brother used US Letter paper size.   How can I handle this error?  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 procedure TForm1.ListBox2DblClick(Sender: TObject);begin   Printers.Printer.SetPrinter(ListBox2.Items[ListBox2.ItemIndex]);   try    Printer.PaperSize.PaperName := printer.PaperSize.DefaultPaperName;  except    showmessage('Yes');    Printer.PaperSize.PaperName := 'Shipping';  end;   ShowMessage(Printer.PaperSize.PaperName);   Panel1.Invalidate; end; ---------------------------------------------------------------------- jamie · 2020-07-24 01:49 my guess is and it is most likely that is you didn't call the EndDOC method to complete the current selected printer operation so its still there.  The other option is to first SetPrinter('') nothing, change the values and then SetPrinter to what you want. ---------------------------------------------------------------------- Dan3468298 · 2020-07-24 02:10 I never executed BeginDoc.  Just inspecting and setting properties. ---------------------------------------------------------------------- Dan3468298 · 2020-07-24 12:18 SetPrinter('') did not help.  Current code and errors attached.   Appreciate the help! 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 procedure TForm1.ListBox2DblClick(Sender: TObject);begin  if ListBox2.ItemIndex <> -1 Then    try      Printers.Printer.SetPrinter(ListBox2.Items[ListBox2.ItemIndex]);      Printer.PaperSize.PaperName := printer.PaperSize.DefaultPaperName;    except      on E: Exception do        ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );    end;   Panel1.Invalidate; end; ---------------------------------------------------------------------- jamie · 2020-07-24 14:34 Ok so instead changing the name. First change the paper size and the the printer name. Also maybe u want a try and finally instead so u can complete the operation. Run it outside of debug mode. ---------------------------------------------------------------------- Dan3468298 · 2020-07-24 15:13 OK, changed the order of the property changes and changed try from except to finally.  Same US Letter not supported error but now worse since code gets stuck there without changing the printer.  Code: 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 procedure TForm1.ListBox2DblClick(Sender: TObject);begin   if ListBox2.ItemIndex <> -1 Then    try      Printer.PaperSize.PaperName := printer.PaperSize.DefaultPaperName;      Printers.Printer.SetPrinter(ListBox2.Items[ListBox2.ItemIndex]);    //except    //  on E: Exception do    //    ShowMessage( 'Error: '+ E.ClassName + #13#10 + E.Message );    finally      //place holder    end;   Panel1.Invalidate; end; ---------------------------------------------------------------------- winni · 2020-07-24 15:25 Hi! Before you set a paper size ,you should ask your printer which formats are supported: procedure TPrinter.DoEnumPapers(Lst: TStrings); Now you can select one format from the list Lst. Winni ---------------------------------------------------------------------- Dan3468298 · 2020-07-24 16:35 Quote from: winni on July 24, 2020, 05:25:59 pmHi! Before you set a paper size ,you should ask your printer which formats are supported: procedure TPrinter.DoEnumPapers(Lst: TStrings); Now you can select one format from the list Lst. Winni Being a newbie I am not sure how to make the call to DoEnumPapers.  This is an unpublished function?  Please give me an example.  Thx! ---------------------------------------------------------------------- howardpc · 2020-07-24 17:19 Try this. Start a new Lazarus GUI application. In the Project Inspector add a new requirement for the printer4lazarus package. Drop a listbox on the form. Double-click the form to generate an OnCreate handler. Complete it as follows: 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 uses    ... PrintersDlgs, ...;procedure TForm1.FormCreate(Sender: TObject);var  dlg: TPrintDialog;begin  dlg := TPrintDialog.Create(Nil);  try    if dlg.Execute then      ListBox1.Items.Assign(Printer.PaperSize.SupportedPapers);  finally    dlg.Free;  end;end;If you click the Print button in the dialog that shows when the app starts, it will populate the listbox with whatever paper sizes your default printer supports. ---------------------------------------------------------------------- Dan3468298 · 2020-07-24 21:40 Thanks for the useful replies! ---------------------------------------------------------------------- skalogryz · 2020-07-25 03:55 This is might widgetset specific implementation problem. You might want to try to replicate the same problem under Win32. (Just make sure you don't use the workaround code). If you cannot replicate the problem under Win32. (i.e. switching the printer does not retain the paper size) Then you might want to file a bug report regarding Cocoa implementation of printers. Note, that you might be the person that's held responsible for the proper testing of the fix. The nature of the issue is very hardware specific. Most of the printers that usual people get hands on do support "Letter" and "A4". ---------------------------------------------------------------------- Dan3468298 · 2020-07-27 17:12 I only have MacOS Catalina now.  I am thinking about using Parallels to install Windows 10 but not rushing on that.  I am trying currently to get Trunk install running. ---------------------------------------------------------------------- Dan3468298 · 2020-07-29 22:36 I have Trunk running now so am going to license Parallels and Windows 10.