Главная страница
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.012 c
1-73271
no_login
2002-05-11 00:37
2002.05.23
Деловое предложение! Есть такой модуль... windows.pas...


1-73183
Катерина
2002-05-14 10:54
2002.05.23
Заголовок окна в ShowMessage


3-73042
Pokotskiy
2002-04-25 15:15
2002.05.23
Помогите обновить DBgrid при работе с Interbase таблицой!!!!


1-73315
Deus
2002-05-12 01:16
2002.05.23
проблемы с hint ом


3-73091
vne
2002-04-26 15:17
2002.05.23
Как получить Extended или Double простым SQL?