Ver Mensaje Individual
  #1  
Antiguo 08-04-2008
richard187 richard187 is offline
Registrado
 
Registrado: abr 2008
Posts: 5
Reputación: 0
richard187 Va por buen camino
Smile evento onclick del button

hola.

soy nuevo en esto del entorno de delphi

me dieron una tarea sobre pilas y colas para ke desarrolle un programa con su interfaz grafica

kisiera ke me ayuden en un problema que tengo al programar el evento onclic del button

tengo las siguientes funciones y procedimietos OPP
el problema ya esta casi resuelto, cree una aplicacion y una unit nueva

la unit uPilas es la siguiente..
( en esto no hay problemas )

Cita:
unit uPilas;
interface
uses StdCtrls, Dialogs;
const maxpila=10;
type
tipoinfo = string ;
TPila = object
private
tope: 0..maxpila;
items:array [1..maxpila]of tipoinfo;
public
constructor init;
function vacia:boolean;
function llena:boolean;
procedure insertar(x: tipoinfo);
function eliminar:tipoinfo;
end;
implementation
constructor TPila.init;
begin
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.
en la segunda unidad donde se llaman a las funciones lo hice de la siguiente manera..
en realidad es aqui donde me pierdo.. no se como llamar correctamente
en si el programa se ejecuta normal, pero al momento de insertar o eliminar un elemento me sale un error por fa ayudenme

la unit ufPilas de la forma es la siguiente:

Cita:
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
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses uPilas;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var p: TPila;
begin
p.init;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
eInsertar.SetFocus;
eInsertar.SelectAll;
end;
procedure TForm1.bInsertarClick(Sender: TObject);
var p: TPila;
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 p: TPila; x: Tpila;
begin
p.eliminar();
lbmostrar.Items.delete(lbmostrar.Items.InstanceSize);
end;

end.

espero me ayuden
Responder Con Cita