INI文件记载要打印的信息, 格式:
[1]
caption=abcd
font=宋体
size=14
left=2
top=2.5
[2]
caption=中国人
font=楷体_GB2312
size=18
left=6
top=4代码如下:(其中strList存储INI文件各节的名称)
  Printer.BeginDoc;
  for i := 0 to strList.Count-1 do
    begin
      SectionName := strList.Strings[i];
      sCaption := F.ReadString(SectionName, 'caption', 'error');
      sFont := F.ReadString(SectionName, 'font', 'error');
      sSize := F.ReadString(SectionName, 'size', 'error');
      sLeft := F.ReadString(SectionName, 'left', 'error');
      sTop := F.ReadString(SectionName, 'top', 'error');
      try
        printer.Canvas.Font.Name := sFont;
        printer.Canvas.font.Size := strtoint(sSize);
        printer.canvas.textout(trunc(strtofloat(sLeft)/2.54*fx),
        trunc(strtofloat(sTop)/2.54*fx), sCaption);
      except
        Printer.Abort;        // 出错情况下中止打印
        raise;
      end;
    end;
  Printer.EndDoc;但是执行打印的时候却没有反应,如果把Printer.BeginDoc和Printer.Abort放在try语句中,则会打印出多篇纸(一节一张),请问怎样才能让for循环中的内容在一张纸上打印出来?

解决方案 »

  1.   

    Printer.BeginDoc;
     try
      for i := 0 to strList.Count-1 do
        begin
          SectionName := strList.Strings[i];
          sCaption := F.ReadString(SectionName, 'caption', 'error');
          sFont := F.ReadString(SectionName, 'font', 'error');
          sSize := F.ReadString(SectionName, 'size', 'error');
          sLeft := F.ReadString(SectionName, 'left', 'error');
          sTop := F.ReadString(SectionName, 'top', 'error');
            printer.Canvas.Font.Name := sFont;
            printer.Canvas.font.Size := strtoint(sSize);
            printer.canvas.textout(trunc(strtofloat(sLeft)/2.54*fx),
            trunc(strtofloat(sTop)/2.54*fx), sCaption);
        end;
        except
         Printer.Abort;        // 出错情况下中止打印
         raise;
        end;
      Printer.EndDoc;把循环放在Try里面去