Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2002.05.23;
Скачать: CL | DM;

Вниз

Как сохранить из StringGrid в текстовый файл   Найти похожие ветки 

 
Как сделать? ©   (2002-05-14 18:36) [0]

Вот код:

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;

Почему то при сохранении выдает ошибку????


 
Anatoly Podgoretsky ©   (2002-05-14 18:40) [1]

stringlist := TStringList.Create;

...
StringList.Free;
end;

Но я посоветую другой метод, смотри следующее сообщение


 
MBo ©   (2002-05-14 18:42) [2]

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;


 
MBo ©   (2002-05-14 18:44) [3]

да, в самом конце
StringList.Free;


 
Anatoly Podgoretsky ©   (2002-05-14 18:47) [4]

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;


 
Song ©   (2002-05-14 19:26) [5]

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);


 
Как сделать? ©   (2002-05-15 00:54) [6]

Спасибо !!! Выручили!!!



Страницы: 1 вся ветка

Текущий архив: 2002.05.23;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.014 c
1-73270
kay
2002-05-10 23:37
2002.05.23
Excel


1-73274
Igg
2002-05-11 01:38
2002.05.23
Хинты


3-73012
SONY
2002-04-26 06:59
2002.05.23
Ошибка


14-73356
Rooman
2002-04-14 09:09
2002.05.23
А законна ли экспертиза системного блока вообще?


6-73330
SerVS - S
2002-03-12 16:50
2002.05.23
Variant + TCP