2010年12月14日 星期二

QcickReport換行範例

函數:判斷是否中文
function IsLeadByteTw(InStr : String):Boolean;
var ws:widestring;
begin
   ws:=InStr;
   if IntToHex(Word(ws[Length(WS)]),2)='00' then
       Result := True // 中文
   else // 英文
       Result := False;
end;

換行實作範例
procedure DetailBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
var
  a : integer;
  b, Str : string;
  AString : TStringList;
  ROWS : integer;
begin
  inherited;
  rows := 0;
  //決定BANK的高度。
  QRLabel3.Caption := '';
//  QRMemo1.Lines.Clear;
  b:='';
  AString := TStringList.Create;
  AString.Text := cdsPrintSCUNO.AsString;
  QRLabel3.Caption := '';
  if trim(AString.Text) <> '' then
  begin
    for a:= 0 to Astring.Count -1 do
    begin
     b := b + StringReplace(Trim(Astring.Strings[a]),'?','',[rfReplaceAll]);
    end;

    While Length(b) > 0 do
    begin
      Str := Copy(b, 1, 80);
      if IsLeadByteTw(Str) then
      begin
         Str := Copy(b, 1, 80);
         Delete(b, 1, 81);
      end
      else
         Delete(b, 1, 80);
      QRLabel3.Caption := QRLabel3.Caption + Str + #13;
//      QRMemo1.Lines.Add(Str);
      rows := rows + 1;
    end;
  end;
  AString.Free;
//  showmessage(inttostr(rows));
//  QRMemo1.Height := 16*rows;
  QRLabel3.Height := 16*rows;
  DetailBand1.Height := 20 + (rows-1)*16;
end;