数据源是逗号分隔的文本文件,没有标题行,也没有行序号字段,数据是标准的二维表格内容。我想在DELPHI 7 中建立表格式的界面,读文本文件数据,并能编辑(增加,删除,修改),能固定第一行,第一列,最好能显示行序号,然后将修改后的数据保存到原来的文本文件中。我是DELPHI 初学者,目前看到TStringGrid ,TF1book,TDBGrid显示的界面是表格形式的,想请教:
在众多控件中,用哪个最合适,最方便(因为我水平比较低)?先谢谢各位热心朋友。

解决方案 »

  1.   

    显示用上面那些是可以的。
    读取的话,建议是用TStringList
      

  2.   

    TMS AdvStringGrid
    ===用非DELPHI的内置控件,程序编译后,是否还需要这个控件支持,就是一起发布?
      

  3.   

    就用D自带的TStringGrid
    自己写一个读写函数就可以了
      

  4.   

    http://www.delphibox.com/article.asp?articleid=559我下载了TMS TAdvStringGrid v1.94 根据下面的安装提示Installation of TAdvStringGrid
    -------------------------------Delphi 3,4,5,6 Open the file ASGDx.DPK, compile and install the package.
    提示
    没有advgrid.pas文件编译无法通过,从其他网站下载的也是这个情况。另外,这个控件是要付费的吧?
      

  5.   

    用DBGRID就可以!!
    楼主说的应该是CSV文件,只需要在ODBC中建立一个数据源,在DELPHI中用SELECT * FROM 文件名即可,与操作表相同!
      

  6.   

    经过自己不断的摸索(我学d才几天),读,写的功能都实现了,还实现了列宽自动调整为最合适的功能。//写
    procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName);
    var
      f: TextFile;
      i, k: Integer;
      rowstr: string;
    begin
      AssignFile(f, FileName);
      Rewrite(f);
      with StringGrid do
      begin
        for i := 1 to rowCount - 1 do //
        begin
          rowstr := '';
          for k := 1 to colCount - 1 do //
          (*begin
            if k=1 then
           //µÚÒ»¸ö ×Ö¶Î
              rowstr := cells[k, i]
            else
              rowstr := rowstr + ',' + cells[k, i];
          end;*)
         //----------------------------
          begin
            if k = 1 then
              rowstr := cells[k, i] + ',' //
            else
              if k = colcount - 1 then //
                rowstr := rowstr + cells[k, i]
              else
                rowstr := rowstr + cells[k, i] + ','; //
          end;
          //---------------------------------------------
          Writeln(F, rowstr); //
        end;
      end;
      CloseFile(F);
    end;//读
    procedure TForm1.Button3Click(Sender: TObject);var
      aa, bb: tstringlist;
      i, col: integer;
    begin
      aa := tstringlist.Create;
      bb := tstringlist.Create;
      if opendialog1.Execute then  aa.LoadFromFile(opendialog1.filename);  stringgrid1.RowCount := aa.count + 1;
      stringgrid1.Cells[0, 0] := 'ÐòºÅ';  for i := 0 to aa.Count - 1 do
      begin
        for col := 1 to fngetpartcount(aa.strings[i], ',') do
        begin
          if fngetpartcount(aa.Strings[i], ',') > stringgrid1.ColCount then
            stringgrid1.ColCount := fngetpartcount(aa.Strings[i], ',') + 1;
          stringgrid1.cells[0, i + 1] := inttostr(i + 1);
          stringgrid1.cells[col, i + 1] := fnGetPartString(aa.strings[i], col, ',');    end;
      end;  for i := 1 to stringgrid1.ColCount do
      begin
        stringgrid1.Cells[i, 0] := 'µÚ' + inttostr(i) + 'ÁÐ';
      end;  SetOptimalGridCellWidth(stringgrid1, [0..0]);  aa.Free;
      bb.Free;end;
    procedure SetOptimalGridCellWidth(sg: TStringGrid;
      ExcludeColumns: TExcludeColumns);
    var
      i: Integer;
      j: Integer;
      max_width: Integer;
    begin
      with sg do
      begin
          // If the grid's Paint method hasn't been called yet,
          // the grid's canvas won't use the right font for TextWidth.
          // (TCustomGrid.Paint normally sets this, under DrawCells.)
        Canvas.Font.Assign(Font);
        for i := 0 to (ColCount - 1) do
        begin
          if i in ExcludeColumns then
            Continue;
          max_width := 0;
            // Search for the maximal Text width of the current column.
          for j := 0 to (RowCount - 1) do
            max_width := Math.Max(max_width, Canvas.TextWidth(Cells[i, j]));
            // The hardcode of 4 is based on twice the offset from the left
            // margin in TStringGrid.DrawCell. GridLineWidth is not relevant.
          if max_width > 0 then
            ColWidths[i] := max_width + 4
          else
            ColWidths[i] := DefaultColWidth;
        end; { for }
      end;
    end;
      

  7.   

    数据本身是文本文件*.txt,但和EXCEL 的CSV格式是兼容的,都是逗号分隔。
      

  8.   

    FigoZhu(谢慕安)    
    TStringList============
    是不是没有可视界面的?只能用代码操作?  
     
      

  9.   

    送一个函数给你:
    function strnget(
      const sourStr,slipStr:string;
      const posiInt:integer;
      const daufStr:string):string;
    var
      strTemp :string;
      intLoop :integer;
    begin{截取某个指定字符串后的数据}
      strTemp := sourStr;
    try
      if(sourStr = '') then exit;
      if(slipStr = '') then exit;  intLoop := 1;
      while (intLoop<posiInt) do
      begin
        inc(intLoop);
        strTemp := copy(strPos(PChar(strTemp), PChar(slipStr)), length(slipStr)+1, maxint);
        if(strTemp = '') then exit;
      end;
      intLoop := pos(slipStr, strTemp);
      if(intLoop = 0) then intLoop := maxint;
      strTemp := copy(strTemp, 1, intLoop-1);
    finally
      case (strTemp='') of
        true: result := daufStr;
        else  result := strTemp;
      end;
    end;
    end;用法:strnget(源string, string分割字符:如',', 第几个, 默认值);