Cierto, ahora que lo miré un poco yo lo haría de esta manera:
Código Delphi
[-]
unit uPilas;
interface
uses StdCtrls, Dialogs;
const
maxpila=10;
type
tipoinfo = string ;
TPila = class(Tobject)
private
tope: 0..maxpila;
items:array [1..maxpila]of tipoinfo;
public
constructor Create;
function vacia: boolean;
function llena: boolean;
procedure insertar(x: tipoinfo);
function eliminar: tipoinfo;
end;
implementation
constructor TPila.Create;
begin
inherited Create;
tope:=0;
end;
function TPila.vacia: boolean;
begin
vacia := (tope = 0);
end;
function TPila.llena: boolean;
begin
llena := (tope=maxpila);
end;
function TPila.eliminar: tipoinfo;
begin
if vacia then
ShowMessage('Pila vacia')
else
begin
eliminar:=items[tope];
dec(tope);
end;
end;
procedure TPila.insertar(x: tipoinfo);
begin
if llena then
showmessage('Pila llena')
else
begin
inc(tope);
items[tope] := x;
end;
end;
end.
La unit ufPilas (la del form):
Código Delphi
[-]
unit ufPilas;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
eInsertar: TEdit;
bInsertar: TButton;
bEliminar: TButton;
lbMostrar: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure bInsertarClick(Sender: TObject);
procedure bEliminarClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
uses uPilas;
{$R *.dfm}
var
P: TPila;
procedure TForm1.FormCreate(Sender: TObject);
begin
p := TPila.Create;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
eInsertar.SetFocus;
eInsertar.SelectAll;
end;
procedure TForm1.bInsertarClick(Sender: TObject);
begin
if length(eInsertar.Text) = 0 then
showmessage('texto en blanco')
else
begin
lbmostrar.items.Append(eInsertar.Text);
p.insertar(eInsertar.Text);
eInsertar.setfocus;
eInsertar.SelectAll;
end;
end;
procedure TForm1.bEliminarClick(Sender: TObject);
var
x: Tpila;
begin
p.eliminar();
lbmostrar.Items.delete(lbmostrar.ItemIndex);
end;
end.
Así ya funciona...eso creo
Saludos