Вниз
Скачать: 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 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.009 c
14-73378
mart
2002-04-16 02:41
2002.05.23
Дача


1-73290
lak_b
2002-05-11 14:12
2002.05.23
как сделать форму невидимой(hide) при загрузке


6-73340
igmel
2002-03-13 06:49
2002.05.23
Пинг


1-73159
anod
2002-05-13 23:26
2002.05.23
Чтение из файла


3-73077
RDA
2002-04-28 15:15
2002.05.23
Конвертация базы данных




   Наверх