我在一个listbox对像上添加数据库的记录,可是数据库的内容长度不一,不可整齐列出内容,不知有哪种方法可定制输出字符长度和定制作左右对齐

解决方案 »

  1.   

    function Format(const Format: string; const Args: array of const): string;This example displays a message on the form status bar indicating the table record count after a record is deleted.procedure TForm1.Table1AfterDelete(DataSet: TDataSet);
    begin
      StatusBar1.SimpleText := Format('There are now %d records in the table', [DataSet.RecordCount]);
    end;
      

  2.   

    是不是可以考虑用TAB(#9)分隔字符
      

  3.   

    //str: String;  字符串
    //len: Integer; 格式化字符串的长度
    //AlignValue: Integer  对齐方式 0:Left 1:Center 2: Right
    function myFormat(str: String; len: Integer; AlignValue: Integer):String;
    var ii: Integer;
        sstr: String;
    begin
      sstr := TRIM(str);
      if Length(sstr) >= len then
      begin
        result := copy(sstr,1,len);
        Exit;
      end;
      while len(sstr) < len do
      begin
        case AlignValue of
           0: sstr := sstr + ' ';
           1: sstr := ' '+sstr+' ';
           else sstr := ' '+sstr;
        end; 
      end;
      result := sstr;
    end;