如题.希望能直接通过INIFile操作读写。

解决方案 »

  1.   

    可以写到ini文件
    [行]
    列=值
      

  2.   

    参考代码procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j,m,n:Integer;
      fl:TINIfile;
      path,rowname,colname:string;
    begin
      path:=ExtractFilePath(application.ExeName);
      fl:=TIniFile.Create(path+'param.ini');
      i:=self.StringGrid1.RowCount;
      m:=self.StringGrid1.ColCount;
      fl.WriteInteger('param','rowcount',i-1);
      fl.WriteInteger('param','colcount',m);
      for n:=0 to m-1 do
      begin
        self.StringGrid1.Cells[n,0]:='第'+inttostr(n+1)+'列';
        colname:=self.StringGrid1.Cells[n,0];
        fl.WriteString('colname',IntToStr(n),colname);
        for j:=0 to m-1 do
        begin
          self.StringGrid1.Cells[j,n]:=inttostr(j+1)+'行'+inttostr(n+1)+'列';
          rowname:=self.StringGrid1.Cells[j,n];
          fl.WriteString('rowname',IntToStr(n)+','+inttostr(j),rowname);
        end;
      end;
      fl.Free;
    end;
      

  3.   

    通过ini文件再还原stringgrid的参考代码procedure TForm1.Button2Click(Sender: TObject);
    var
      i,j,m,n:Integer;
      fl:TINIfile;
      path,rowname,colname:string;
    begin
      path:=ExtractFilePath(application.ExeName);
      fl:=TIniFile.Create(path+'param.ini');
      i:=fl.ReadInteger('param','rowcount',0);
      m:=fl.ReadInteger('param','colcount',0);
      if (i=0) or (m=0) then
        Exit;
      self.StringGrid1.RowCount:=i+1;
      self.StringGrid1.ColCount:=m;
      for n:=0 to m-1 do
      begin
        colname:=fl.ReadString('colname',IntToStr(n),'');
        Self.StringGrid1.Cells[n,0]:=colname;
        for j:=0 to i do
        begin
          rowname:=fl.ReadString('rowname',IntToStr(n)+','+inttostr(j),'');
          self.StringGrid1.Cells[n,j]:=rowname;
        end;
      end;
      fl.Free;
    end;