原理:直接对“LPT1”端口进行输出,使用此种方式打印速度是最快的。<br><br>对文本文件进行写操作,当文本文件的文件名为“LPT”或“COM”等保留字里,即是对指定端口写。<br><br>源代码截自“吉胜超市POS” <br>my:='lpt1'; <br>filehandle:=fileopen(my,fmopenwrite); <br>fileclose(filehandle);<br>if filehandle<0 then<br>begin<br>messagebox(handle,'lpt1错误','错误',mb_iconerror);<br>exit;<br>end<br>else<br>begin<br>assignfile(tf,my);<br>rewrite(tf);<br>writeln(tf,chr(27)+chr(112)+chr(0)+chr(18)+chr(22)); <br>with query1 do<br>begin<br>sql.Clear;<br>sql.Add('select 企业名称 from 企业档案');<br>close;<br>open;<br>end;<br>writeln(tf,' '+query1.fieldbyname('企业名称').AsString); <br>if strtofloat(label6.Caption)<0 then<br>writeln(tf,' '+'退货单')<br>else<br>writeln(tf,' '+'销售单');<br>writeln(tf,'流 水 号:'+form1.StatusBar1.Panels[1].Text);<br>writeln(tf,'销售日期:'+datetimetostr(now));<br>writeln(tf,'收 款 员:'+form1.StatusBar1.Panels[3].Text);<br>writeln(tf,'--------------------------------');<br>writeln(tf,'商品编码'+' '+'数量'+' '+'单价'+' '+'金额');<br>writeln(tf,'--------------------------------');<br>for a:=1 to form1.StringGrid1.RowCount-2 do<br>begin<br>writeln(tf,form1.StringGrid1.Cells[2,a]); <br>writeln(tf,form1.StringGrid1.Cells[1,a]+' '+form1.StringGrid1.Cells[5,a]+' '+form1.StringGrid1.Cells[4,a]+' '+form1.StringGrid1.Cells[6,a]); <br>end;<br>writeln(tf,'--------------------------------');<br>writeln(tf,'合计金额:'+' '+Label8.Caption);<br>writeln(tf,'找零金额:'+' '+label9.Caption);<br>writeln(tf,'谢谢惠顾,欢迎下次光临');<br>writeln(tf,'请妥善保管您的电脑小票');<br>writeln(tf,''); <br>writeln(tf,'');<br>writeln(tf,'');<br>writeln(tf,'');<br>writeln(tf,'');<br>closefile(tf);