views:

246

answers:

2

I have been getting sporadic reports of my application (compiled with Delphi 7) refusing to start on some PCs - it exited immediately with the Windows error message:

“....exe has encountered a problem and needs to close. We are sorry for the inconvenience”

My advice up until now has to always been to install a default printer (any printer - even a PDF printer) and the problem goes away. How can I fix the application? My program only access the PrinterDialog controls when the user pushes the Print button.

+2  A: 

I received an email containing a bug report generated by MadExcept with the very helpful stacktrace:

exception class   : EReadError
exception message : Error reading PrinterDialog.Copies: Operation not supported on selected printer.

main thread ($5d4):
0044c0a2  Classes      HandleException
0044c258  Classes      TReader.ReadProperty
0044bbf5  Classes      TReader.ReadDataInner
0044bbd7  Classes      TReader.ReadData
00450675  Classes      TComponent.ReadState
0044ba51  Classes      TReader.ReadComponent
0044bc69  Classes      TReader.ReadDataInner
0044bba8  Classes      TReader.ReadData
00450675  Classes      TComponent.ReadState
004963a5  Controls     TControl.ReadState
004998c9  Controls     TWinControl.ReadState
004afcc9  Forms        TCustomForm.ReadState
0044c9a9  Classes      TReader.ReadRootComponent
00449f42  Classes      TStream.ReadComponent
00446a3b  Classes      InternalReadComponentRes
00446bc5  Classes      InitComponent
00446c56  Classes      InitInheritedComponent
004af661  Forms        TCustomForm.Create
004518b0  Classes      StdWndProc
004b7111  Forms        TApplication.CreateForm
006abe32           176 initialization

The problem is caused by the fact I had set a number of properties of the TPrinterDialog at design time, such as the flag to print page numbers. When Delphi tried to create the form and set these properties on a PC with no printer, the error occurs.

The solution was to delete the old TPrinterDialog and replace it with a new default TPrinterDialog and set the properties at run time once a new printer was installed.

devstopfix
A: 

You could "try except" the crashing statement:

  Try
    Statement
  {Statement...}
  Except
    Statement
  {Statement...}
  End; 

http://www.delphibasics.co.uk/RTL.asp?Name=Try
Further Description of try/except

maxedmelon