unit adt; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type Tdataplay = class(TForm) collection: TLabel; Label1: TLabel; Label2: TLabel; data: TEdit; push: TButton; pop: TButton; enqueue: TButton; dequeue: TButton; done: TButton; t: TLabel; h: TLabel; procedure doneClick(Sender: TObject); procedure pushClick(Sender: TObject); procedure popClick(Sender: TObject); procedure enqueueClick(Sender: TObject); procedure update; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var dataplay: Tdataplay; implementation {$R *.DFM} procedure TDataplay.update; {change the values displayed as head and tail} var long : integer; begin long := length(collection.caption); if long > 0 then begin h.caption := collection.caption[long]; t.caption := collection.caption[1] end else begin h.caption := ''; t.caption := '' end end; procedure Tdataplay.doneClick(Sender: TObject); begin close end; procedure Tdataplay.pushClick(Sender: TObject); begin collection.caption := collection.caption + data.text[1]; update end; procedure Tdataplay.popClick(Sender: TObject); var head : integer; tempstring : string; begin tempstring := collection.caption; {get a copy of what is there} head := length(tempstring); {identify the position of the head of the stack} if head > 0 {the stack is not empty} then begin data.text := tempstring[head]; {get the char at the head} delete(tempstring, head, 1); {now remove that cha from the head} collection.caption := tempstring {now refresh the displayed value} end else showmessage('There is no data left'); update end; procedure Tdataplay.enqueueClick(Sender: TObject); begin collection.caption := data.text[1] + collection.caption; update end; procedure Tdataplay.FormCreate(Sender: TObject); begin update end; end.