unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tperson =
record
name :
string;
id:integer;
end;
TStack =
class
private
Keller :
array[1..4]
of Tperson;
Stackpos : Integer;
i:integer;
public
procedure stackpush;
function stackpop():integer;
function stacktop():integer;
constructor create;
end;
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FStack : Tstack;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor tstack.create;
begin
Stackpos := -1;
end;
procedure tstack.stackpush;
begin
inc(stackpos);
Keller[Stackpos].id := i;
end;
function tstack.stackpop:integer;
begin
result := Keller[Stackpos].id;
dec(stackpos);
end;
function tstack.stacktop:integer;
begin
result := Keller[Stackpos].id;
end;
procedure TForm1.Button1Click(Sender: TObject);
var myrec : Tperson;
begin
myrec.
name := form1.edit1.text;
myrec.id := strtoint(form1.edit2.text);
fstack.stackpush;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
fstack.stacktop;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fstack := tstack.create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
fstack.Free;
end;
end.