Delphi: printer ready and int $17?


[ Delphi Forum -- by DelphiLand ]

Posted by Sheirly Dewi on December 23, 2003 at 05:54:30:

Hello,
I want to ask a question : How to detect in my Delphi app whether the printer power is ON or OFF and how to detect the paper of printer is ready? I use Borland Delphi 7 and Windows 2000.
I try a program, but it always error at -->> int $17 an error is access violation at address ... why???
Thank you very much
Sincerely,
Sheirly

============================== P R O G R A M ==========================================
unit ps1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, printers;
type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
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');
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;
procedure TForm1.Button1Click(Sender: TObject);
var
  L, P : integer;
begin
  P := PrinterStatus;
  ListBox1.Clear;
  for L := 0 to 7 do
    if P and (1 shl L) > 0 then
      ListBox1.Items.Add (PrinterCodes [L]);
end;
end.
 

Related Articles and Replies:


[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]