Setting ActivePrinter changes default printer
Hello,
I have the following code. It appears to me that the call to set up the
ActivePrinter changes the default printer. Is that correct and is there a
better way to chose a printer and print a word document.
Thanks
{Create the OLE object and open up the word document}
WordDocument := CreateOLEObject( 'Word.Application' );
WordDocument.Documents.Open( DocumentPath + DocumentName );
{Now set up the printer. If we still do not have a printer get the
default}
if PrinterNo = -1 then
begin
{Setting PrinterIndex to -1 gives us the default printer}
Printer.PrinterIndex := -1 ;
PrinterNo := Printer.PrinterIndex ;
end ;
{Finally check that we have a valid printer, then tell word to use it}
if (PrinterNo >= 0) and (PrinterNo < Printer.Printers.Count) then
begin
WordDocument.ActivePrinter := printer.Printers[PrinterNo];
{Now print the document}
WordDocument.PrintOut( EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);
{Now wait until word has finished printing}
while WordDocument.BackgroundPrintingStatus > 0 do Sleep( 100 );
end ;
WordDocument.Quit( False ) ;