Jump to content

Recommended Posts

Posted
procedure TfrmCADEXE.BtnIncluirClick(Sender: TObject);
begin

  pilha := Nil;

  begin
  if (pilha = Nil) then
  begin
  new(pilha);

  pilha^.Autor        := EdtNome_Autor.Text;
  pilha^.Nome_da_Obra := EdtNome_Obra.Text;
  pilha^.QTD_Pg       := EdtQtd_Pag.Text;
  pilha^.CEP_Autor    := EdtCEP_Autor.Text;

  pilha^.proximo := nil;
  end
  else
  begin

  aux := pilha;

  while (aux^.proximo <> Nil) do
  new(novo);
  novo^.Autor        := EdtNome_Autor.Text;
  novo^.Nome_da_Obra := EdtNome_Obra.Text;
  novo^.QTD_Pg       := EdtQtd_Pag.Text;
  novo^.CEP_Autor    := EdtCEP_Autor.Text;

  novo^.proximo := Nil;
  aux^.proximo := novo;

  end;
  end;

  ListBox1.Items.Add(pilha^.Autor + ' - ' + pilha^.Nome_da_Obra + ' - ' +  pilha^.QTD_Pg + ' - ' +  pilha^.CEP_Autor);

  EdtNome_Autor.Clear;
  EdtNome_Obra.Clear;
  EdtQtd_Pag.Clear;
  EdtCEP_Autor.Clear;


end;

procedure TfrmCADEXE.BtnRetirarClick(Sender: TObject);
begin

  if (pilha = nil) then
  begin
    ShowMessage('Sem Livros para Retirar');
  end;
  if (pilha <> nil) then
  begin
  aux := pilha;
  While(aux^.proximo <> nil) do
  begin
       penultimo :=  aux;
       aux := aux^.proximo;
  end;
  penultimo^.proximo := nil; // O erro é apontado aqui.//Não está excluindo no topo como gostaria.
  Dispose(aux);
  end;
end;

Estou tentando implementar um projeto de empilhar livros.

Não esta desempilhando.

Help - me.

Posted

Acho que estás sempre a inserir os dados no inicio da pilha.

procedure TfrmCADEXE.BtnIncluirClick(Sender: TObject);
begin

  pilha := Nil;   //  ------- Se dizes que a pilha = NIL

  begin
  if (pilha = Nil) then // -- Então isto é sempre verdade
  begin
  new(pilha);
....

Dá uma olhada aqui: https://www.portugal-a-programar.pt/forums/topic/47424-ponteiros/

ou aqui: https://wiki.portugal-a-programar.pt/dev_geral/pascal/ponteiros/

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.