贴段代码,不过不是我写的!
unit PrinterStatus;
interface
uses
Windows, Messages, WinProcs, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs;
type
TPrinterStatus = class(TComponent)
private
fStatus : Byte;
fLPT : Integer;
Function GetTimeOut : Boolean;
Function GetIOError : Boolean;
Function GetPrinterSelected : Boolean;
Function GetOutOfPaper : Boolean;
Function GetAcknowledgement : Boolean;
Function GetPrinterBusy : Boolean;
public
Procedure CheckPrinterStatus;
Constructor Create(AOwner : TComponent);
Override;
Property TimeOut : Boolean Read GetTimeOut;
Property IOError : Boolean Read GetIOError;
Property PrinterSelected : Boolean Read GetPrinterSelected;
Property OutOfPaper : Boolean Read GetOutOfPaper;
Property Acknowledgement : Boolean Read GetAcknowledgement;
Property Busy : Boolean Read GetPrinterBusy;
end;
implementation
Function TPrinterStatus.GetTimeOut : Boolean;
begin
Result:=(fStatus and $01)=$01;
end;
Function TPrinterStatus.GetIOError : Boolean;
begin
Result:=(fStatus and $08)=$08;
end;
Function TPrinterStatus.GetPrinterSelected : Boolean;
begin
Result:=(fStatus and $10)=$10;
end;
Function TPrinterStatus.GetOutOfPaper : Boolean;
begin
Result:=(fStatus and $20)=$20;
end;
Function TPrinterStatus.GetAcknowledgement : Boolean;
begin
Result:=(fStatus and $40)=$40;
end;
Function TPrinterStatus.GetPrinterBusy : Boolean;
begin
Result:=not ((fStatus and $80)=$80);
end;
Procedure TPrinterStatus.CheckPrinterStatus;
Var
Status : Byte;
CheckLPT : Word;
begin
Status:=0;
If (fLPT>=1) and (fLPT<=3) then
begin
CheckLPT:=fLPT-1;
asm
mov dx,CheckLPT;
mov al,0;
mov ah,2;
int 17h;
mov &Status, ah;
end;
end;
fStatus:=Status;
end;
Constructor TPrinterStatus.Create(AOwner : TComponent);
begin
Inherited Create(AOwner);
fLPT:=1;
fStatus:=0;
end;
end.