我用如下代码在本地打印机上输出就没有问题,可是把WINDOWS的打印机设置修改为局域网内的另一台共享打印机,则出现错误,无法打印,该如何解决(大意是什么读取某地

  • 主题发起人 主题发起人 wp231957
  • 开始时间 开始时间
W

wp231957

Unregistered / Unconfirmed
GUEST, unregistred user!
我用如下代码在本地打印机上输出就没有问题,可是把WINDOWS的打印机设置修改为局域网内的另一台共享打印机,则出现错误,无法打印,该如何解决(大意是什么读取某地址错误) ( 积分: 100 )<br />//打印输出
procedure TForm1.Button19Click(Sender: TObject);
var
prn:tprinter;
m,n:integer;
jie,dai:double;
cow:integer;
page:integer;
begin
jie:=0.00;
dai:=0.00;
prn:=tprinter.Create ;
prn.Canvas.Font.Name := '宋体';
prn.Canvas.Font.Size :=14;
cow:=0;
page:=0;
prn.begin
Doc ;
/////////////////////////////////////////////////
prn.Canvas.TextOut(180,0, combobox3.Text+' 移动备用金明细帐');
prn.Canvas.MoveTo(0,43);
prn.Canvas.LineTo(900,43) ;
//////////////////////////////
query2.Close;
query2.RequestLive:=true;
query2.DatabaseName:='';
query2.SQL.Clear ;
query2.SQL.Text :='select id,datew,zhaiyao,jiefang,daifang,yu_e,wdmc from &quot;base.DBF&quot;
where wdmc=&quot;'+combobox3.Text +'&quot;';
query2.Open ;
m:=10;
//起始列
n:=10;
//起始行
with prn.Canvasdo
begin
textout(m,n+35,'日期');
textout(m+210,n+35,'摘要');
textout(m+410,n+35,'借方');
textout(m+590,n+35,'贷方');
textout(m+770,n+35,'余额');
MoveTo(0,n+66);
LineTo(900,n+66) ;
end;
n:=n+35;
prn.Canvas.TextOut(m,n+35,'初始备用金');
query3.Close;
query3.RequestLive:=true;
query3.DatabaseName:='';
query3.SQL.Clear ;
query3.SQL.Text :='select wdmc,byjinit,jieyu from &quot;beiyj.DBF&quot;
where wdmc=&quot;'+combobox3.Text+'&quot;' ;
query3.Open ;
prn.Canvas.TextOut(m+720,n+35,nspace(formatfloat('0.00',query3.fieldbyname('byjinit').AsFloat),10)) ;
n:=n+35;
while not query2.Eofdo
begin
with prn.Canvasdo
begin
textout(m,n+35,nspace(datetimetostr(query2.fieldbyname('datew').asdatetime),10));
textout(m+190,n+35,query2.fieldbyname('zhaiyao').AsString);
textout(m+360,n+35,nspace(formatfloat('0.00',query2.fieldbyname('jiefang').AsFloat),10));
textout(m+540,n+35,nspace(formatfloat('0.00',query2.fieldbyname('daifang').AsFloat),10));
textout(m+720,n+35,nspace(formatfloat('0.00',query2.fieldbyname('yu_e').AsFloat),10));
jie:=jie+query2.fieldbyname('jiefang').AsFloat;
dai:=dai+query2.fieldbyname('daifang').AsFloat;
inc(cow);
if cow=50 then
begin
inc(page);
MoveTo(0,n+70);
LineTo(900,n+70) ;
textout(10,n+94,'过次页('+inttostr(page)+')');
prn.NewPage ;
//新的一页
/////////////////////////////////////////////////
prn.Canvas.TextOut(180,0, combobox3.Text+' 移动备用金明细帐');
prn.Canvas.MoveTo(0,43);
prn.Canvas.LineTo(900,43) ;
//////////////////////////////
n:=10;
cow:=0;
textout(m,n+35,'日期');
textout(m+210,n+35,'摘要');
textout(m+410,n+35,'借方');
textout(m+590,n+35,'贷方');
textout(m+770,n+35,'余额');
MoveTo(0,n+66);
LineTo(900,n+66) ;
textout(10,n+80,'承前页');
n:=n+60;
end;
query2.Next ;
n:=n+35;
end;
end;
with prn.Canvasdo
begin
MoveTo(0,n+50);
LineTo(900,n+50) ;
inc(page);
textout(20,n+55,'合计 共('+inttostr(page)+')页');
textout(m+380,n+55,formatfloat('0.00',jie));
textout(m+580,n+55,formatfloat('0.00',dai));
textout(20,n+99,'记帐');
textout(200,n+99,'主管');
textout(400,n+99,'打印日期:'+datetimetostr(now));
end;
////////////////////////////////////////////////
prn.EndDoc ;
end;
 
最可能的原因是你没有访问共享打印机的权限!
可以先用WORD 打印试试!
 
最可能的原因是你没有访问共享打印机的权限!
可以先用WORD 打印试试!
没问题
我打印WINDOWS测试页,一点问题都没有
 
调试一下:找出错误出现在哪条语句上?
完整的错误信息是什么?
 
直接用 printer:
//打印输出
procedure TForm1.Button19Click(Sender: TObject);var
m,n:integer;
jie,dai:double;
cow:integer;
page:integer;
begin
jie:=0.00;
dai:=0.00;
Printer.Canvas.Font.Name := '宋体';
Printer.Canvas.Font.Size :=14;
cow:=0;
page:=0;
Printer.begin
Doc ;
/////////////////////////////////////////////////
Printer.Canvas.TextOut(180,0, combobox3.Text+' 移动备用金明细帐');
Printer.Canvas.MoveTo(0,43);
Printer.Canvas.LineTo(900,43) ;
//////////////////////////////
query2.Close;
query2.RequestLive:=true;
query2.DatabaseName:='';
query2.SQL.Clear ;
query2.SQL.Text :='select id,datew,zhaiyao,jiefang,daifang,yu_e,wdmc from &quot;base.DBF&quot;
where wdmc=&quot;'+combobox3.Text +'&quot;';
query2.Open ;
m:=10;
//起始列
n:=10;
//起始行
with Printer.Canvasdo
begin
textout(m,n+35,'日期');
textout(m+210,n+35,'摘要');
textout(m+410,n+35,'借方');
textout(m+590,n+35,'贷方');
textout(m+770,n+35,'余额');
MoveTo(0,n+66);
LineTo(900,n+66) ;
end;
n:=n+35;
Printer.Canvas.TextOut(m,n+35,'初始备用金');
query3.Close;
query3.RequestLive:=true;
query3.DatabaseName:='';
query3.SQL.Clear ;
query3.SQL.Text :='select wdmc,byjinit,jieyu from &quot;beiyj.DBF&quot;
where wdmc=&quot;'+combobox3.Text+'&quot;' ;
query3.Open ;
Printer.Canvas.TextOut(m+720,n+35,nspace(formatfloat('0.00',query3.fieldbyname('byjinit').AsFloat),10)) ;
n:=n+35;
while not query2.Eofdo
begin
with Printer.Canvasdo
begin
textout(m,n+35,nspace(datetimetostr(query2.fieldbyname('datew').asdatetime),10));
textout(m+190,n+35,query2.fieldbyname('zhaiyao').AsString);
textout(m+360,n+35,nspace(formatfloat('0.00',query2.fieldbyname('jiefang').AsFloat),10));
textout(m+540,n+35,nspace(formatfloat('0.00',query2.fieldbyname('daifang').AsFloat),10));
textout(m+720,n+35,nspace(formatfloat('0.00',query2.fieldbyname('yu_e').AsFloat),10));
jie:=jie+query2.fieldbyname('jiefang').AsFloat;
dai:=dai+query2.fieldbyname('daifang').AsFloat;
inc(cow);
if cow=50 then
begin
inc(page);
MoveTo(0,n+70);
LineTo(900,n+70) ;
textout(10,n+94,'过次页('+inttostr(page)+')');
Printer.NewPage ;
//新的一页
/////////////////////////////////////////////////
Printer.Canvas.TextOut(180,0, combobox3.Text+' 移动备用金明细帐');
Printer.Canvas.MoveTo(0,43);
Printer.Canvas.LineTo(900,43) ;
//////////////////////////////
n:=10;
cow:=0;
textout(m,n+35,'日期');
textout(m+210,n+35,'摘要');
textout(m+410,n+35,'借方');
textout(m+590,n+35,'贷方');
textout(m+770,n+35,'余额');
MoveTo(0,n+66);
LineTo(900,n+66) ;
textout(10,n+80,'承前页');
n:=n+60;
end;
query2.Next ;
n:=n+35;
end;
end;
with Printer.Canvasdo
begin
MoveTo(0,n+50);
LineTo(900,n+50) ;
inc(page);
textout(20,n+55,'合计 共('+inttostr(page)+')页');
textout(m+380,n+55,formatfloat('0.00',jie));
textout(m+580,n+55,formatfloat('0.00',dai));
textout(20,n+99,'记帐');
textout(200,n+99,'主管');
textout(400,n+99,'打印日期:'+datetimetostr(now));
end;
////////////////////////////////////////////////
Printer.EndDoc ;
end;
 
后退
顶部