tags:

views:

526

answers:

1

I have created a Delphi service which is responsible for printing QuckReports to specific printers contained within the printer.Printers list. I pass my routine the printer name and it looks up in the printer.printers array to get the proper index. It then does this:

QuickRep1.PrinterSettings.PrinterIndex := iIndex;

In the help files it says this for printer.refresh: "Call Refresh when the installed fonts or printers on the current system may have changed". So I call the refresh before I look up the printer name against the printer.printers array.

At one of my installations this function is not working properly. If printers are added/deleted, or someone with printers under their profiles logs on, the list does not seem to get refreshed until the service is stopped and restarted.

Does this function not work for services? The installation where this is occurring utilizes "virtual services". Could this have anything to do with it?

Thanks.

+2  A: 

My experience and understanding is the printers array is updated only at application start. Anytime a new printer is installed, the application must be restarted to get the correct list.

I'm curious to hear any different experience with this myself.

EDIT: From my comment below; I wrote a small test program that confirms the TPrinters.Refresh() does update the printers list.

dverespey
The array is loaded the first time the TPrinters.GetPrinters() method is called. Subsequent calls do not refresh the list. TPrinter does have a Refresh() method if you need to refresh individual printers, though.
Remy Lebeau - TeamB
<<TPrinter does have a Refresh() method if you need to refresh individual printers>> - it does not appear to refresh the list though. Does it only refresh an individual printer? I will create a test application and a test service to see if I can find out more.
M Schenkel
Well I feel silly, simple test program(D7, XP) and refresh did clear the entire printer TStringList. A subsequent check of the Printers list contained the correct list. It didn't seem to work at one point long ago, but it could have just been the haze of QR issues.Back to yours, possible as a service it's login is affecting what it can see?
dverespey
@dverespey you should update your answer with new information
Toby Allen