我用QuickReport 做的报表,其中有一栏“缴费信息”,需要将各个缴费项目(最多5个,我用了5个dbtext:item1,item2,item3,item4,item5;并且每条记录的缴费项目数不定)按顺序排列在这一栏里。因此需要在程序里动态设定它们的位置。我是这样设定的:
   try
    application.CreateForm(Tfrmdetailqryprev,frmdetailqryprev);
    with frmdetailqryprev do
    begin
      for i:=1 to table1.recordcount do  //table1是QuickRep连接的DataSet  
      begin
        item1.Left:=180;
        item2.Left:=item1.Left+trunc(item1.Size.Width)+8;
        item3.Left:=item2.Left+trunc(item2.Size.Width)+8;
        item4.Left:=item3.Left+trunc(item3.Size.Width)+8;
        item5.Left:=item4.Left+trunc(item4.Size.Width)+8;
        table1.Next;
      end;
    end;
    frmdetailqryprev.QuickRep1.Preview;
  except
     on EAccessViolation do
     begin
       frmdetailqryprev.free;
     end;
  end;  可程序运行时,几个item的排列间隔却很近,没有达到预期目的,这是什么原因?

解决方案 »

  1.   

    将类似这样
            item1.Left:=180;
            item2.Left:=item1.Left+trunc(item1.Size.Width)+8;
            item3.Left:=item2.Left+trunc(item2.Size.Width)+8;
            item4.Left:=item3.Left+trunc(item3.Size.Width)+8;
            item5.Left:=item4.Left+trunc(item4.Size.Width)+8;
    调整left属性的语句写在相应band的onshow事件内。
    (具体事件的名称记不清楚,大概是这样的)
      

  2.   

    你的几个Item的AutoSize是不是true,如果是的话,他会根据你每行的具体取值自动计算Item的Width,也就是说你在CreateForm时根本无法得到Item的具体取值
      

  3.   

    to  daniel007(添) : 
       正如你说所的那样,我是把几个item的AUTOSIZE属性设成TRUE。TO ScoutKing:
       BAND没有onshow事件,我正尝试放在BEFOREPRINT 中试试
      

  4.   

    我改成以下程序:
    procedure Tfrmdetailqryprev.QRBand4BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    begin
      item1.Left:=168;
      item2.Left:=item1.Left+item1.Width+8;
      item3.Left:=item2.Left+item2.Width+8;
      item4.Left:=item3.Left+item3.Width+8;
      item5.Left:=item4.Left+item4.Width+8;
    end;
      可还是不行,各位高手,该怎么改呢