![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как сохранить из StringGrid в текстовый файл [D6, NT4]
Как сделать? © (2002-05-14 18:36:00)Вот код:
procedure TForm1.N11Click(Sender: TObject);
var
i,j:integer;
stringlist:TStrings;
s:string;
begin
Stringlist.Create;
for i:=Form1.StringGrid1.FixedRows to Form1.StringGrid1.RowCount-1 do
begin
s:="";
for j:=Form1.StringGrid1.FixedCols to Form1.StringGrid1.ColCount-1 do
begin
if j<Form1.StringGrid1.ColCount-1 then
s:=s+Form1.StringGrid1.Cells[j,i]
else
s:=s+"|"+ Form1.StringGrid1.Cells[j,i];
StringList.Add(s);
end;
end;
stringlist.SaveToFile("c:\name.txt");
end;
Почему то при сохранении выдает ошибку????
Как сделать? (2002-05-15 00:54:00) [1]Спасибо !!! Выручили!!!
Song (2002-05-14 19:26:00) [2]Var FileHandle,t,n,StringLen:Integer;
x:String[250];
....
FileHandle:=FileCreate(S);
FileWrite(FileHandle,ColCount,SizeOf(ColCount));
FileWrite(FileHandle,RowCount,SizeOf(RowCount));
For t:=0 to RowCount-1 Do
For n:=0 to ColCount-1 Do
Begin
StringLen:=Length(Cells[n,t])+1;
FileWrite(FileHandle,StringLen,SizeOf(StringLen));
x:=Cells[n,t];
FileWrite(FileHandle,X,StringLen);
End;
FileClose(FileHandle);
Anatoly Podgoretsky (2002-05-14 18:47:00) [3]var
I,J : Integer;
F : TextFile;
begin
AssignFile(f,"c:\name.txt");
Rewrite(f);
WriteLn(f,RowCount,ColCount,FixedRows,FixedCols);
for I := 0 to RowCount - 1 do begin
for J := 0 to ColCount - 1 do begin
WriteLn(f,Grid.Cels[J,I]);
end;
end;
CloseFile(f);
end;
MBo (2002-05-14 18:44:00) [4]да, в самом конце
StringList.Free;
MBo (2002-05-14 18:42:00) [5]procedure TForm1.N11Click(Sender: TObject);
var
i,j:integer;
stringlist:TStringList;
s:string;
begin
Stringlist:=TStringList.Create;
for i:=StringGrid1.FixedRows to StringGrid1.RowCount-1 do begin
s:="";
for j:=StringGrid1.FixedCols to StringGrid1.ColCount-1 do
if j=Form1.StringGrid1.ColCount-1 then
s:=s+Form1.StringGrid1.Cells[j,i]
else
s:=s+ Form1.StringGrid1.Cells[j,i]+"|";
StringList.Add(s);
end;
stringlist.SaveToFile("c:\name.txt");
end;
Anatoly Podgoretsky (2002-05-14 18:40:00) [6]stringlist := TStringList.Create;
...
StringList.Free;
end;
Но я посоветую другой метод, смотри следующее сообщение