如何把StringGrid1中的内容保存到文件中?
菜鸟求详解,越详细越好,最好给代码加注释,痛哭流涕的表示感激。 本帖最后由 aminghanhua 于 2013-6-20 16:02 编辑procedure SaveGrid(g:TStringGrid; filename:string);
var i:integer;
t:TStringlist;
begin
t:=TStringlist.Create;
for i:=0 to g.RowCount-1 do
begin
g.Rows.Delimiter:=',';
t.Add(g.Rows.DelimitedText);
end;
t.SaveToFile(filename);
t.Free;end;
procedure LoadGrid(g:TStringGrid; filename:string);
var i:integer;
t:TStringlist;
begin t:=TStringlist.Create;
t.LoadFromFile(filename);
g.RowCount:=t.Count;
for i:=0 to t.Count-1 do
begin
g.Rows.Delimiter:=',';
g.Rows.DelimitedText:=t.Strings;
end;
t.Free;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
SaveGrid(StringGrid1,'f.txt');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LoadGrid(StringGrid1,'f.txt');
end; 楼上写的能实现
+1 先留着以后用
页:
[1]