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