(* 检查打印机状态 *)
function Check: boolean;
var
Status: Byte;
PaperOut, Selected, IOError, TimeOut: Boolean;
FTime: TDateTime;
FMessage: string;
begin
FTime := Time;
repeat
Status := $40;
while (( Status and $80 ) = 0 ) and (( Status and $40 ) <> 0 )do
asm
MOV AH, 2
MOV DX, 0
INT 17H
MOV Status, AH
end;
if ( Status and $01 ) <> 0 then
TimeOut := True else
TimeOut := False;
if ( Status and $08 ) <> 0 then
IOError := True else
IOError := False;
if ( Status and $10 ) <> 0 then
Selected := True else
Selected := False;
if ( Status and $20 ) <> 0 then
PaperOut := True else
PaperOut := False;
if TimeOut then
begin
result := false;
FMessage := '打印机超时!(' + IntToHex( Status, 2 ) + ')';
end else
if Selected and PaperOut and IOError then
begin
result := false;
FMessage := '打印机缺纸!(' + IntToHex( Status, 2 ) + ')';
end else
if Selected and PaperOut then
begin
result := false;
FMessage := '打印机没有联机!(' + IntToHex( Status, 2 ) + ')';
end else
if IOError then
begin
result := false;
FMessage := '打印机没有联机!(' + IntToHex( Status, 2 ) + ')';
end else
result := true;
until result or ( Time - FTime > 10*1.157407407E-6 );
if ( not result ) and ( MessageDlg( FMessage + #13#10'继续重试?', mtWarning, [ mbOK, mbCancel ], 0 ) = mrCancel ) then
raise EAbort.Create( FMessage );
end;