We got a Code from our teacher which should represent a working Linked List. But the Problem is, that i can not Add anything. When i try to add something with an Button i get this Pup op. I tried to change aktpos with Liste but it did not work either. I am always getting this Error meassage:
This is my current Code:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
Label1: TLabel;
procedure deleClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure nachClick(Sender: TObject);
procedure neuesClick(Sender: TObject);
procedure prevClick(Sender: TObject);
private
public
end;
TListe= Class
Zahl: Integer;
next,prev: TListe;
procedure einfuegen();
procedure loeschen();
procedure naechstes();
procedure vorgaenger();
end;
var
Form1: TForm1;
Liste, aktPos: TListe;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Liste:= TListe.create;
Liste.Zahl:=0;
Liste.prev:=Liste;
Liste.next:= Liste;
Form1.Edit1.Text:=IntToSTr(Liste.Zahl);
aktPos:=Liste;
end;
procedure TForm1.nachClick(Sender: TObject);
begin
aktpos.naechstes();
end;
procedure TForm1.neuesClick(Sender: TObject);
begin
aktpos.einfuegen();
end;
procedure TForm1.prevClick(Sender: TObject);
begin
aktpos.vorgaenger();
end;
procedure TForm1.deleClick(Sender: TObject);
begin
aktpos.loeschen();
end;
procedure TListe.einfuegen();
var new,hilf:TListe;
eingabe:string;
begin
hilf:=aktpos.next;
new:=TListe.create;
Form1.Edit1.Text:='';
repeat
eingabe := InputBox('NeuesElement', 'Zahleingeben', '');
until eingabe <> '';
new.Zahl:=StrToInt(eingabe);
new.next:=hilf;
new.prev:=aktPos;
aktpos.next:=new;
hilf.prev:=new;
Form1.Edit1.Text:=IntToSTr(aktpos.Zahl);
end;
procedure TListe.loeschen();
var hilf:TListe;
begin
hilf:=aktPos;
aktPos:=aktpos.next;
aktpos.prev:=hilf.prev;
aktpos.prev.next:=aktpos;
hilf.destroy;
Form1.Edit1.Text:=IntToSTr(aktpos.Zahl);
end;
procedure TListe.naechstes();
begin
aktPos:=aktpos.next;
Form1.Edit1.Text:=IntToSTr(aktPos.Zahl);
end;
procedure TListe.vorgaenger();
begin
aktPos:=aktpos.prev;
Form1.Edit1.Text:=IntToSTr(aktPos.Zahl);
end;
end.
end.
```
I am not sure if the Problem is perhabs on the lines before, therefore i am posting the complete Code. I tried my best to fix the Code but could not make it because it is my first time programming recursive.