Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Для новичков > StringGrid сохранение и добавление данных


Автор: Ratty 28.3.2008, 22:43
Доброго времени суток! Буду краток. Пишу курсовую что-то в виде базы данных только использую StringGrid.
Более или менее работает. И все бы ничего если не один бок.
Я добавляю данные в StringGrid, сохраняю через SaveDialog и открываю через OpenDialog дальше добавляю и тд. Все работает на УРА.
Но, только я закрою прогу и снова открою, открываю сохраненный *.txt  он уже не добавляет данные в StringGrid. В чем ошибка? Помогите отыскать! Времени в обрез, код привожу ниже:

 
Код

procedure TForm2.BitBtn1Click(Sender: TObject);//Add
begin
  begin
 if (Form1.StringGrid1.Cells[0, 1] <> '') and  (Form1.StringGrid2.Cells[0, 1] <> '')
    then
    begin
     Form1.StringGrid1.RowCount := Form1.StringGrid1.RowCount + 1;
     Form1.StringGrid2.RowCount := Form1.StringGrid2.RowCount + 1;
    end;
  end;
  i := Form1.StringGrid1.RowCount-1;
  Form1.StringGrid1.Cells[0,i]:=IntToStr(i);
  Form1.StringGrid2.Cells[0,i]:=IntToStr(i);
Form1.StringGrid1.Cells[1,i]:=Edit1.Text;
Form1.StringGrid1.Cells[2,i]:=Edit2.Text;
Form1.StringGrid1.Cells[3,i]:=Edit3.Text;
Form1.StringGrid1.Cells[4,i]:=Edit5.Text;
Form1.StringGrid1.Cells[5,i]:=Edit4.Text;
end;

procedure TForm1.N10Click(Sender: TObject);//Open
var
  FName: string;
  F: textfile;
  temp, x, y: integer;
  tempstr: string;
 begin
if OpenDialog1.Execute then
 begin
 FName := OpenDialog1.FileName;
  AssignFile(F,  FName);
  Reset(F);
  Readln(F, temp);
  StringGrid1.ColCount := temp;
  Readln(F, temp);
  StringGrid1.RowCount := temp;
  for X := 0 to StringGrid1.Colcount - 1 do
  for y := 0 to StringGrid1.Rowcount - 1 do
    begin
      Readln(F, tempstr);
      StringGrid1.Cells[x, y] := tempstr;
    end;
 CloseFile(F);
end;

procedure TForm1.N12Click(Sender: TObject);//Save as...
var
FName:string;
 F: textfile;
 x, y: integer;
begin
SaveDialog1.FileName := FName;
if SaveDialog1.Execute then
 begin
  FName := SaveDialog1.FileName;
 AssignFile(F, FName+'.txt');
 Rewrite(F);
 Writeln(F, StringGrid1.Colcount);
 Writeln(F, StringGrid1.Rowcount);
 for X := 0 to StringGrid1.Colcount - 1 do
 for y := 0 to StringGrid1.Rowcount - 1 do
  Writeln(F, StringGrid1.Cells[x, y]);
 CloseFile(F);
end;
end;

Автор: imageman 3.4.2008, 19:25
похоже проблема в этой строке
Код

 if (Form1.StringGrid1.Cells[0, 1] <> '') and  (Form1.StringGrid2.Cells[0, 1] <> '')

Автор: Ratty 4.4.2008, 17:30
Действительно! Спасибо за подсказку

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)