Problemy ze StringGrid

0

witam,
Chciałbym aby cała zawartość tabeli (wypelniona przez uzytkownika) byla zapisana przez przycisk do pliku (np *.txt). Pozniej po uruchomieniu programu ponownie klikajac na przycisk zeby dane z pliku byly atomatycznie wczytywane do tabeli. Da sie cos takiego zrobic??
A jezeli tak to prosze o wskazowki...

0
Procedure SaveGrid;
var f:textfile;
x,y:integer;
begin
assignfile (f,'Filename');
rewrite (f);
writeln (f,stringgrid.colcount);
writeln (f,stringgrid.rowcount);
For X:=0 to stringgrid.colcount-1 do
        For y:=0 to stringgrid.rowcount-1 do
writeln (F, stringgrid.cells[x,y]);
closefile (f);
end;
 
Procedure LoadGrid;
var f:textfile;
temp,x,y:integer;
tempstr:string;
begin
assignfile (f,'Filename');
reset (f);
readln (f,temp);
stringgrid.colcount:=temp;
readln (f,temp);
stringgrid.rowcount:=temp;
For X:=0 to stringgrid.colcount-1 do
        For y:=0 to stringgrid.rowcount-1 do begin
        readln (F, tempstr);
        stringgrid.cells[x,y]:=tempstr;
        end;
closefile (f);
end;
0

Jak zadziała, będę Ci bardzo bardzo wdzięczny... [cya]

Tylko jak tą procedurę podpiąć pod przycisk??

0

Tylko jak tą procedurę podpiąć pod przycisk??

jaja se z nas robisz ? :|

http://4programmers.net/file.php?id=81

0
procedure TForm1.Button1Click(Sender: TObject);
begin
savegrid;
end;

procedure TForm.Button1Click(Sender: TObject);
begin
loadgrid;
end;
0

No i jest cos takiego. Sorki ze tak zawracam glowe, ale bardzo mi na tym zalezy. A tu wszedzi sa bledy. Pierwsze gdzie sie czepia jest zaznaczone na czerwono

To źródło (przepraszam ze bedzie dlugo ale coz)

type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
procedure wypelnij_tabele(var s:TstringGrid);
var i:integer;
begin
with s do begin
Cells[0,0]:='przedmioty';
Cells[0,1]:='Polski';
Cells[0,2]:='Matematyka';
Cells[0,3]:='Angileski';
Cells[0,4]:='Informatyka';
Cells[0,5]:='Chemia';
Cells[0,6]:='Fizyka';
Cells[0,7]:='Biologia';
Cells[0,8]:='Muzyka';
Cells[0,9]:='WF';
for i:=1 to 9 do
cells[i,0]:='ocena';
end;
end;

procedure SaveGrid;
var f:textfile;
x,y:integer;
begin
assignfile (f,'C:\tabela.txt');
rewrite (f);
writeln (f,StringGrid1.colcount);<------- Tu cos nie pasuje
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;

procedure LoadGrid;
var f:textfile;
temp,x,y:integer;
tempstr:string;
begin
assignfile (f,'C:\tabela.txt');
reset (f);
readln (f,temp);
stringgrid.colcount:=temp;
readln (f,temp);
stringgrid.rowcount:=temp;
for X:=0 to stringgrid.colcount-1 do
for y:=0 to stringgrid.rowcount-1 do begin
readln (F, tempstr);
stringgrid.cells[x,y]:=tempstr;
end;
closefile (f);
end;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
wypelnij_tabele(StringGrid1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SaveGrid;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
LoadGrid;
end;

end.

begin
wypelnij_tabele(Stringgrid1);
end;

end.

0
<quote> writeln (f,StringGrid1.colcount);<------- Tu cos nie pasuje

moze napisalbyc co ci wyrzuca kompilator??? latwiej by troche bylo

0

jak na mój gust to pewnie, że konwersja, czyli

IntToStr 

załatwia sprawę

1 użytkowników online, w tym zalogowanych: 0, gości: 1