原理:直接对“LPT1”端口进行输出,使用此种方式打印速度是最快的。对文本文件进行写操作,当文本文件的文件名为“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);我想直接对LPT1”端口进行输出主表和明细表的信息,上面的程序是我从网上摘录的,我看不明白,不知道各位有没有这方面的资料呢?
我的主表是
编号   金额     时间
01     10.12  2007-09-19明细表是
编号 主表编号  数量 单价
1    01      1    5
2    01      1    5.12

解决方案 »

  1.   

    my:= 'lpt1 ';  
    filehandle:=fileopen(my,fmopenwrite);  
    fileclose(filehandle); filehandle是什么?
    fileopen是什么函数?
    filehandle:=fileopen(my,fmopenwrite);  达到什么功能?
    writeln(tf,chr(27)+chr(112)+chr(0)+chr(18)+chr(22));  达到什么功能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]);  这一段代码是把数据表的信息一条条打印出来,但有一个问题的:就是CELLS[2,A]的长度不一样时,造成排版对不齐的
    比如商品编码  数量 单价 金额
    001      1   2    2  
    012456      2     3     6当然是这个例子商品编码位数是一样,长度是一样,但当打印的是商品名时就对不齐了
    请问各位高手,有没有解决方法,WRITELN如何精确定位
      

  2.   

    Tm-U210针式打印机:
       AssignFile(f, 'LPT1');
       rewrite(f);
       write(f,chr(27)+chr(64));   //初始化打印头   write(f,chr(27)+chr(33)+chr(0)); // 英文正常大小
       write(f,chr(28)+chr(33)+chr(0)); // 中文正常大小
       writeln(f,'ABC打印测试ABC');   write(f,chr(27)+chr(33)+chr(16)); // 英文倍高模式
       write(f,chr(28)+chr(33)+chr(8));  //中文倍高模式
       writeln(f,'ABC打印测试ABC');   write(f,chr(27)+chr(33)+chr(32)); // 英文倍宽模式
       write(f,chr(28)+chr(33)+chr(4));  //中文倍宽模式
       writeln(f,'ABC打印测试ABC');   write(f,chr(27)+chr(33)+chr(48)); // 英文倍高倍宽模式
       write(f,chr(28)+chr(33)+chr(12));  //中文倍高倍宽模式
       writeln(f,'ABC打印测试ABC');   writeln(f,chr(10));   //换行
       closefile(f);这是直接调用打印机的代码,我不明白里面的参数是什么意思,请高手们教一教
      

  3.   

    这些都是打印机的指令集,一般针对某种特种型号的打印机,不过也有的厂商的打印的指令集是统一的,比如zebra的 zpl.
    这些代码没有什么价值.
      

  4.   

    如果只向端口发送可用如下代码, APrintStr是要打印的数据var
      tfPrint: TextFile;
      APrintStr: String;
    begin
      try
        APrintStr:=APrintStr+chr(10);
        AssignFile(tfPrint, 'lpt1');
        Rewrite(tfPrint);
        Write(tfPrint, APrintStr);
        CloseFile(tfPrint);
      Except
      End;chr(27)+chr(33)+chr(0)这些都是ESC /pos打印控制命令
    命令说明参考
    http://topic.csdn.net/t/20040216/22/2741183.html
      

  5.   

    搂住要搞清楚到底想快还是想解决排版问题。
    文本文件的对其一般是用tab来解决的。
      

  6.   

    filehandle是一个句柄变量,就是指向你打开文件的指针,FILLOPEN是一个打开文件的函数,相当于通用对话框的COMMONDIALOG1.SHOWOPEN,WRITELN是写一行。