Главная страница
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.48 MB
Время: 0.013 c
3-72996
RedKat
2002-04-24 19:28
2002.05.23
Програмное создание ADO ConnectionString


1-73234
ДимкаН
2002-05-15 09:33
2002.05.23
Автоматизация и Excel


3-73092
phantom2040
2002-04-27 13:45
2002.05.23
BDGrid


1-73273
demon-777
2002-05-10 12:29
2002.05.23
Tinifille


4-73465
vitall
2002-03-25 13:21
2002.05.23
Подскажите, где ошибка? Вроде все правильно, но не работает...