Gvicente Posted July 17, 2018 at 06:15 PM Report #611370 Posted July 17, 2018 at 06:15 PM 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.
passarito Posted July 19, 2018 at 11:54 PM Report #611398 Posted July 19, 2018 at 11:54 PM 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/
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now