AV when installing printers on the fly
Hi!
My app is running on NT server as a service and responds to user's requests.
The app should be able to install new printer on the fly if it necessary.
Sometimes the users submit invalid printer name and system generates error
1801. 'The printer name is invalid'. So far so good!
Unfortunately when the next request arrives with correct printer name RB
generates AV.
You can find below a snippet of code, which reproduces the problem. Am I
doing anything wrong? How to fix the problem?
I found a temporary solution: ALL cashed ppReport components are released
and recreated in case of error 1801. As you can guess this is not
satisfactory solution because it affects system performance.
I am using D6sp2 and RB6.03 on W2k/NT
Appreciate any feedback.
Irek
Irek Rybark
Siemens Hearing Instruments Inc.
procedure TForm1.PrintDocument(APrinterName: string);
begin
try
if ppReport.PrinterSetup.PrinterName <> APrinterName then
begin
// If the requested printer is not defined, try to install it on the
fly
if ppPrinters.PrinterNames.Indexof(APrinterName) < 0 then
AddPrinter(APrinterName);
ppReport.PrinterSetup.PrinterName := APrinterName;
end;
ppReport.Print;
except
on E: Exception do
raise Exception.Create('Error printing document. [' + E.Message +
']');
end;
end;
procedure TForm1.AddPrinter(APrinterName: string);
begin
try
// first try to make sure that we have the latest printer info
ppPrinters.Refresh;
if ppPrinters.PrinterNames.Indexof(APrinterName) < 0 then
begin
// Printer was still not found, try to add the printer
if not AddPrinterConnection(PChar(APrinterName)) then
RaiseLastOSError;
ppPrinters.Refresh;
end;
except
on E: Exception do
raise Exception.Create('Printer (' + APrinterName + ') could not be
added [' +
E.Message + ']')
end;
end;
My app is running on NT server as a service and responds to user's requests.
The app should be able to install new printer on the fly if it necessary.
Sometimes the users submit invalid printer name and system generates error
1801. 'The printer name is invalid'. So far so good!
Unfortunately when the next request arrives with correct printer name RB
generates AV.
You can find below a snippet of code, which reproduces the problem. Am I
doing anything wrong? How to fix the problem?
I found a temporary solution: ALL cashed ppReport components are released
and recreated in case of error 1801. As you can guess this is not
satisfactory solution because it affects system performance.
I am using D6sp2 and RB6.03 on W2k/NT
Appreciate any feedback.
Irek
Irek Rybark
Siemens Hearing Instruments Inc.
procedure TForm1.PrintDocument(APrinterName: string);
begin
try
if ppReport.PrinterSetup.PrinterName <> APrinterName then
begin
// If the requested printer is not defined, try to install it on the
fly
if ppPrinters.PrinterNames.Indexof(APrinterName) < 0 then
AddPrinter(APrinterName);
ppReport.PrinterSetup.PrinterName := APrinterName;
end;
ppReport.Print;
except
on E: Exception do
raise Exception.Create('Error printing document. [' + E.Message +
']');
end;
end;
procedure TForm1.AddPrinter(APrinterName: string);
begin
try
// first try to make sure that we have the latest printer info
ppPrinters.Refresh;
if ppPrinters.PrinterNames.Indexof(APrinterName) < 0 then
begin
// Printer was still not found, try to add the printer
if not AddPrinterConnection(PChar(APrinterName)) then
RaiseLastOSError;
ppPrinters.Refresh;
end;
except
on E: Exception do
raise Exception.Create('Printer (' + APrinterName + ') could not be
added [' +
E.Message + ']')
end;
end;
This discussion has been closed.
Comments
ReportBuilder 6.03 is not thread safe. Please download the trial version of
ReportBuilder 7.02 Server Edition. RB 7.02 is completely thread safe and
comes with many improvements and features that will help you solve the issue
you are having.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com