Mega Code Archive

 
Categories / Delphi / Printing
 

Getting Printer Status

Title: Getting Printer Status.. Question: How to detect printer status? Answer: function PrinterStatus : integer; asm mov ah, 2 // function 2 - returns status of port mov dx, 0 // lpt1 = 0, lpt2 = 1 etc int $17 // status in ah mov al, ah and eax, $FF // status now in eax with top 24 bits cleared end; const PrinterCodes : array [0..7] of string = ('printer timed-out', 'unused', 'unused', 'I/O error', 'printer selected', 'out of paper', 'printer acknowedgment', 'printer not busy'); procedure TForm1.Button1Click(Sender: TObject); var L,P : integer; begin P := PrinterStatus; //status of printer in P ListBox1.Clear; for L := 0 to 7 do if P and (1 shl L) 0 then ListBox1.Items.Add (PrinterCodes [L]); end;