×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Delphi
Posted by: Piotr Trocewicz
Added: Aug 24, 2012 8:21 AM
Modified: Aug 24, 2012 8:44 AM
Views: 99
If you see error like "selected printer is not valid"
  1. procedure TPrinter.SetPrinterIndex(Value: Integer);
  2.     // ----- Begin NEW PART -----
  3. var
  4.   lDevice, lDriver, lPort : Array[0..255] of Char;
  5.   lDeviceMode : Cardinal;
  6.     // ----- End NEW PART -----
  7. begin
  8.     CheckPrinting(False);
  9.     if (Value = -1) or (PrinterIndex = -1) then
  10.         SetToDefaultPrinter
  11.     else
  12.     begin
  13.         if (Value < 0) or (Value >= Printers.Count) then
  14.             RaiseError(SPrinterIndexError);
  15.         FPrinterIndex := Value;
  16.  
  17.         // ----- Begin NEW PART -----
  18.         Printer.GetPrinter(lDevice, lDriver, lPort, lDeviceMode);
  19.         GlobalUnlock(lDeviceMode);
  20.         GlobalFree(lDeviceMode);
  21.         lDeviceMode := 0;
  22.         Printer.SetPrinter(lDevice, lDriver, lPort, lDeviceMode);
  23.     // ----- End NEW PART -----
  24.     end;
  25.         FreeFonts;
  26.     SetState(psNoHandle);
  27. end;