数据打印!(100分)

  • 主题发起人 主题发起人 ggu
  • 开始时间 开始时间
G

ggu

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,我曾经遇到一个问题,在程序中向并口发送数据,送到打印机打印,
请问怎样才能判断并口上是否连接有打印机,用try.....except ....不可以。
请各位指导!
 
(* 检查打印机状态 *)
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;
 
谢谢了!给你100分!
 

Similar threads

回复
0
查看
848
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
后退
顶部