
19.04.2008, 15:13
|
Активный
|
|
Регистрация: 24.03.2008
Сообщения: 227
Версия Delphi: Delphi 7
Репутация: 30
|
|
Цитата:
Сообщение от AndrYxo
Знаю, что плохо... спасибо) 
|
Сохранение в файл 3-х разных таблиц.
Код:
procedure TForm1.BitBtn2Click(Sender: TObject);
var
s :TStringlist;
j:Integer;
Str:String;
posy, posx, i : Integer;
Begin
with TSaveDialog.Create(Owner) do
begin
DefaultExt:='.txt';
Filter:= 'файлы проекта|*.txt';
if not Execute then exit;
s:=TStringList.Create;
s.Clear;
for i:=0 to StringGrid1.RowCount-1 do
begin
Str := '' ;
for j:=0 to StringGrid1.ColCount-1 do
str:=str+StringGrid1.Cells[j, i]+' ';
s.Add(Str);
end;
s.Add('T2');
for i:=0 to StringGrid2.RowCount-1 do
begin
Str := '' ;
for j:=0 to StringGrid2.ColCount-1 do
str:=str+StringGrid2.Cells[j, i]+' ';
s.Add(Str);
end;
s.Add('T3');
for i:=0 to StringGrid3.RowCount-1 do
begin
Str := '' ;
for j:=0 to StringGrid3.ColCount-1 do
str:=str+StringGrid3.Cells[j, i]+' ';
s.Add(Str);
end;
S.SaveToFile(FileName);
end;
s.Free;
end;
Чтение из файла 3-х таблиц.
Код:
procedure TForm1.BitBtn3Click(Sender: TObject);
var
s :TStringlist;
i,j,yd:Integer;
Str:String;
posy, posx, py: Integer;
t1,t2,t3:boolean;
Begin
t1:=true;
t2:=false;
t3:=false;
with TOpenDialog.Create(Owner) do
begin
py:=0;
DefaultExt:='.txt';
Filter:= 'файлы проекта|*.txt';
if not Execute then exit;
s:=TStringList.Create;
S.LoadFromFile(FileName);
For posy := 1 to S.Count do
begin
posx := 0;
Str := '';
For i := 1 to Length(S.Strings[posy-1]) do
begin
if S.Strings[posy-1][i] <> ' ' then
begin
Str := Str + S.Strings[posy-1][i];
if Str = 'T2' then
begin
t1:=false;
t2:=true;
py:=posy;
end;
if Str = 'T3' then
begin
t1:=false;
t2:=false;
t3:=true;
py:=posy;
end;
end
else
begin
if t1= true then StringGrid4.Cells[posx, posy-1] := Str;
if t2 = true then StringGrid5.Cells[posx, posy-1-py] := Str;
if t3 = true then StringGrid6.Cells[posx, posy-1-py] := Str;
Str := '';
inc(posx);
end;
end;
end;
end;
S.Free;
end;
У самого уже бошка кипит 
|