QRLABEL或者QRMEMO怎么实现自动换行

解决方案 »

  1.   

    将WrapWord设为true
    英文字母的自动换行是按单词的
    即 必须有空格 才会自动换或Label1.Caption:='1234566'+#13+'123412341';
      

  2.   

    //换行
    procedure row_change(qr: tquickrep; sender: TQRCustomLabel; var Value:
      String); 
    var
      SenderWidth: integer;
      Line, Part, Final: string;
      PosBegin, PosEnd: integer;
      i, j: integer;
      LastIsEng: boolean;
    begin
      SenderWidth := Sender.Width;
      Part := '';
      Final := '';
      Line := Value;  // 首先删除行内所有换行
      while pos(#10, Line) > 0 do
        Delete(Line, Pos(#10, Line), 1);  // 增加一个回车以方便下面的处理.
      if Line[Length(Line)] <> #13 then Line := Line + #13;  //循环查找#13,如果找到则处理找到范围内的数据,一直到全部处理完毕
      PosBegin := 0;
      PosEnd := 0;
      for i := 1 to Length(Line) do
      begin
        if Line[i] = #13 then
        begin
          PosBegin := PosEnd + 1;
            // 这样可以在处理下一段的时候方便地生成开始和结束位置.
          PosEnd := i;      Part := '';
          j := PosBegin;
          while j <= PosEnd do
          begin
            if Line[j] < #128 then
            begin // an ascii character
              Part := Part + Line[j];
              j := j + 1;
              LastIsEng := true;
            end
            else
            begin // a DBCS character
              Part := Part + Line[j] + Line[j + 1];
              j := j + 2;
              LastIsEng := false;
            end;
            // 判断目前是否已经超长
            if qr.TextWidth(Sender.Font, part) > SenderWidth then
            begin
              // 需要剔除刚才的字符,
              if LastIsEng then
              begin
                Delete(Part, Length(Part), 1);
                j := j - 1;
              end
              else
              begin
                Delete(Part, Length(Part) - 1, 2);
                j := j - 2;
              end;
              //加入回车,
              Part := Part + #13;
              Final := Final + Part;
              Part := '';
            end;
          end;
          Final := Final + Part;
        end;
      end;
      // 删除刚刚加入的回车
      if Final[Length(Final)] = #13 then
        Delete(Final, Length(Final), 1);
      Value := Final;
    end;
      

  3.   

    把上面的过程放到QRDBTEXT或QRDBMEMO的ONPINT事件中
    如:
    procedure TListRep_SDForm_PL.QRDBTxtMake_KYPrint(sender: TObject;
      var Value: String);
    begin
        sysdb.row_change(qr_AB, Sender as TQRCustomLabel , Value );
    end;