Witam napisałem taka o to procedure dodającą elemety do listy i wyświetlającą te elementy w stringgridzie.
type
pprogList = ^progData;
progData = record
data1 : ShortString;
data2 : ShortString;
data3 : ShortString;
data4 : ShortString;
id : integer;
pointer : pprogList;
end;
var
pFirst, pCurrent : pprogList;
procedure TForm1.Button1Click(Sender: TObject); //DO LISTY
var
pPrevious, pNext:pprogList;
begin
z:=z+1;
if pCurrent<>nil
then begin
pPrevious:=pCurrent;
pNext:=pCurrent^.pointer;
end
else
begin
pPrevious:=nil;
pNext:=nil;
end;
New(pCurrent);
with pCurrent^ do
begin
data1:= Edit1.Text;
data2:= Edit2.Text;
data3:= Edit3.Text;
data4:= Edit4.Text;
id:=z;
pointer:=pNext;
end;
if pPrevious<>nil
then pPrevious^.pointer:=pCurrent;
StringGrid1.Cells[0,z]:=pCurrent^.data1;
StringGrid1.Cells[1,z]:=pCurrent^.data2;
StringGrid1.Cells[2,z]:=pCurrent^.data3;
StringGrid1.Cells[3,z]:=pCurrent^.data4;
StringGrid1.Cells[4,z]:=inttostr(pCurrent^.Id);
StringGrid1.RowCount:=z+1;
end;
Czy funkcja napisana przeze mnie jest prawidłowa bo gdy następnie próbuje zapisać listę do pliku (i dla sprawdzenia wyświetlić w innym stringGridzie) to tak jakby lista była pusta
Procedura zapisu wygląda natępująco:
procedure TForm1.Button4Click(Sender: TObject);
var
i : integer;
rec:progData;
plik: file of progData;
pPrevious:pprogList;
begin
pCurrent := pFirst;
i := 1;
assignfile(plik,'C:\plik');
rewrite(plik);
while pCurrent <> nil do
begin
StringGrid2.Cells[0,i] := pCurrent^.data1;
StringGrid2.Cells[1,i] := pCurrent^.data2;
StringGrid2.Cells[2,i] := pCurrent^.data3;
StringGrid2.Cells[3,i] := pCurrent^.data4;
StringGrid2.Cells[4,i] :=inttostr( pCurrent^.id);
rec.data1:=pCurrent^.data1;
rec.data2:=pCurrent^.data2;
rec.data3:=pCurrent^.data3;
rec.data4:=pCurrent^.data4;
rec.id:=pCurrent^.id;
write(plik, rec);
pPrevious := pCurrent;
pCurrent := pPrevious^.pointer;
i := i+1;
end;
closefile(plik);
end;
Proszę o sprawdzenie kodu i jakieś podpowiedzi...