M Schenkel
M Schenkel

Reputation: 6364

QuickReport throws "There Is No Default Printer Currently Selected" Exception

I have created a Delphi Service which prints TQuickReports. Everything works fine if compiled and run as a Windows Application. But when converted to operate as a service trying to create a form containing a TQuickRep component throws the exception.

This service runs fine on many other boxes but not this one in particular. Here are some details:

Upvotes: 4

Views: 24987

Answers (8)

Keesjan van Efferen
Keesjan van Efferen

Reputation: 21

Actually it is a Delphi(5) problem. The comparison of the available printers and the default printer is case sensitive (Printers.pas):

if TPrinterDevice(Objects[I]).Device = Device then
begin
   with TPrinterDevice(Objects[I]) do
      SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
   Exit;
end;

Changing the comparison to: if lowercase(TPrinterDevice(Objects[I]).Device) = lowercase(Device) solves the problem.

Upvotes: 2

Rotary
Rotary

Reputation: 1

I solved a similar problem: If a Delphi application (or service) uses QuickReport, it runs before the system loads the default printer (or printers).

  • When QuickReport executes TQRPrinter.Init, the printer.printers.count is zero,
  • shortly after the system loads, the printer.printers.count is the number of printers,
  • but tqrprinter.int has already executed, so TQRPrinter.FPrinterOK is false,
  • you then see this error when you try open a QuickReport.

The solution for me was wait until the printers were loaded before launching the application (in citrix and terminal server). I solved this in two ways, either by overwriting tqrprinter or delay the dpr.

Upvotes: 0

Niek H.
Niek H.

Reputation: 595

You can solve this problem by creating a new dword UserSelectedDefault with the value: 1 in HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\Session_ID

Make sure you have a local printer selected.

Upvotes: 4

Han
Han

Reputation: 21

We had a simular problem here. Using TS servers, Citrix and Powerfuse 9. Powerfuse had all printers capitalized, however they were shared in a mixed case. This combination caused Delphi/QReport to crash

When all printers are from printserver to powerfuse in the same case (not important upper or lower or even mixed), the problem was gone

Upvotes: 2

Akko
Akko

Reputation: 1

If using terminal services 2008, same user for multiple sessions, you should look into the:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\Session_ID 

instead of

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\

Upvotes: 0

M Schenkel
M Schenkel

Reputation: 6364

A colleague ended up finding the solution. I should have added these are "network" printers and not Local printers (at the time I didn't think this was related to the problem). So the service needed to be installed with "NetworkService" as the user account under the logon tab. From the Windows Help:

To specify that the service uses the Network Service account, click This account, and then type NT AUTHORITY\NetworkService

Upvotes: 2

Marcus Adams
Marcus Adams

Reputation: 53830

You might give the user a way to select the printer for the service. The Windows service probably does not have a default printer set.

Set TQuickRep.PrinterSettings.PrinterIndex to set the printer number. Then, TQuickRep.Print to print the report.

Upvotes: 2

Mihai Limbășan
Mihai Limbășan

Reputation: 67576

Is there a default printer set up in session 0? Remember that under Vista / Server 2008 / Windows 7, services run in a separate session. Whether or not the logged-in user has a default printer set is not relevant - it's a per-session setting and doesn't affect session 0.

Can you rewrite the code to gracefully handle that exception and pick a printer to use?

Upvotes: 6

Related Questions