Qué es una LISTA.??
Altas
Consultas
Bajas
Modificar
Bonus
| Listas de Doble Enlace | |
Listas Circulares |
| VOLVER | |
Archivo | |
Base de Dato | |
Arbol | |
Matriz y Vector |
.. ahora si este te interesa un comino...!!!, te puedo demostrar que ..
LISTAS DINAMICAS
Por la simple lectura del siguiente código es muy sencillo que actives los objetos que se operan y luego puedes copiar estos algoritmos para manejar una lista como estructura de datos dinámica en sus versiones de enlace simple, doble y circular.
En este link también podrás aprender a manipular los archivos de datos de múltiples campos, tarea que te resultará sencilla si conoces tales procesos en lenguaje Pascal.
unit UListas; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, Mask, ExtCtrls, Menus; type //DECLARACION PARA LISTA SIMPLE nodoS=^registroS; registroS=record codigo:integer; nombre:string; cantante:string; preCosto:string; preVenta:string; cantidad:integer; siguiente:nodoS; end; //DECLARACION PARA LISTA DOBLE nodoD=^registroD; registroD=record codigo:integer; nombre:string; cantante:string; preCosto:string; preVenta:string; cantidad:integer; siguiente,anterior:nodoD; end; //DECLARACION PARA LISTA CIRCULAR nodoC=^registroC; registroC=record codigo:integer; nombre:string; cantante:string; preCosto:string; preVenta:string; cantidad:integer; siguiente,anterior:nodoC; end; type TFormListas = class(TForm) Menu: TMainMenu; ListaSimple: TMenuItem; Altas1: TMenuItem; Bajas1: TMenuItem; Modificaciones1: TMenuItem; N1: TMenuItem; Ordenar1: TMenuItem; PorCodigo1: TMenuItem; PorNombre1: TMenuItem; N2: TMenuItem; Listado1: TMenuItem; N3: TMenuItem; Salir1: TMenuItem; ListaDoble: TMenuItem; Altas2: TMenuItem; Bajas2: TMenuItem; Modificaciones2: TMenuItem; N4: TMenuItem; OrdenarProducto1: TMenuItem; PorCodigo2: TMenuItem; PorNombre2: TMenuItem; N5: TMenuItem; Listado2: TMenuItem; N6: TMenuItem; Salir2: TMenuItem; ListaCircular: TMenuItem; Altas3: TMenuItem; Bajas3: TMenuItem; Modificaciones3: TMenuItem; N7: TMenuItem; OrdenarProducto2: TMenuItem; PorCodigo3: TMenuItem; PorNombre3: TMenuItem; N8: TMenuItem; Listado3: TMenuItem; N9: TMenuItem; Salir3: TMenuItem; Ayuda: TMenuItem; Codificacion1: TMenuItem; ListaSimple2: TMenuItem; ListaDoble2: TMenuItem; ListaCircular2: TMenuItem; Acercade1: TMenuItem; N10: TMenuItem; Autores: TMenuItem; N11: TMenuItem; Salir4: TMenuItem; Image1: TImage; PanelAltas: TPanel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; LabelTitulo: TLabel; BoxNombre: TEdit; BoxCantante: TEdit; BoxPreCosto: TEdit; BoxPreVenta: TEdit; BGrabar: TBitBtn; BLimpiar: TBitBtn; BSalirAltas: TBitBtn; ComboCodigo: TComboBox; BModificar: TBitBtn; BEliminar: TBitBtn; PanelCantidad: TPanel; Label8: TLabel; Label9: TLabel; BOk: TBitBtn; BoxCantidad: TEdit; BoxCantidad2: TEdit; BoxCodigo: TEdit; codificacion: TMenuItem; UnitClave: TMenuItem; UnitPrincipal: TMenuItem; UnitAyuda: TMenuItem; UnitVisualizacion: TMenuItem; procedure FormActivate(Sender: TObject); function BuscarCod(cod:String ): boolean; procedure Salir1Click(Sender: TObject); procedure Salir2Click(Sender: TObject); procedure Salir3Click(Sender: TObject); procedure Salir4Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Altas1Click(Sender: TObject); procedure BLimpiarClick(Sender: TObject); procedure BSalirAltasClick(Sender: TObject); procedure BGrabarClick(Sender: TObject); procedure BOkClick(Sender: TObject); procedure Altas2Click(Sender: TObject); procedure Altas3Click(Sender: TObject); procedure ordenarSimple(ord: integer); procedure ordenarDoble(ord: integer); procedure ordenarCircular(ord: integer); procedure PorCodigo1Click(Sender: TObject); procedure PorNombre1Click(Sender: TObject); procedure PorCodigo2Click(Sender: TObject); procedure PorNombre2Click(Sender: TObject); procedure PorCodigo3Click(Sender: TObject); procedure PorNombre3Click(Sender: TObject); procedure Modificaciones1Click(Sender: TObject); procedure Modificaciones2Click(Sender: TObject); procedure Modificaciones3Click(Sender: TObject); procedure BModificarClick(Sender: TObject); procedure ComboCodigoChange(Sender: TObject); procedure Bajas1Click(Sender: TObject); procedure Bajas2Click(Sender: TObject); procedure Bajas3Click(Sender: TObject); procedure BEliminarClick(Sender: TObject); procedure Listado1Click(Sender: TObject); procedure Listado2Click(Sender: TObject); procedure Listado3Click(Sender: TObject); procedure Acercade1Click(Sender: TObject); procedure AutoresClick(Sender: TObject); procedure BoxNombreKeyPress(Sender: TObject; var Key: Char); procedure BoxCantanteKeyPress(Sender: TObject; var Key: Char); procedure BoxPreCostoKeyPress(Sender: TObject; var Key: Char); procedure BoxPreVentaKeyPress(Sender: TObject; var Key: Char); procedure BoxCantidadKeyPress(Sender: TObject; var Key: Char); procedure BoxCodigoKeyPress(Sender: TObject; var Key: Char); procedure BoxCantidad2KeyPress(Sender: TObject; var Key: Char); procedure ListaSimple2Click(Sender: TObject); procedure ListaDoble2Click(Sender: TObject); procedure ListaCircular2Click(Sender: TObject); procedure Validar(num:String); procedure BoxCodigoExit(Sender: TObject); procedure BoxPreCostoExit(Sender: TObject); procedure BoxPreVentaExit(Sender: TObject); procedure BoxCantidadExit(Sender: TObject); procedure BoxCantidad2Exit(Sender: TObject); procedure UnitClaveClick(Sender: TObject); procedure UnitPrincipalClick(Sender: TObject); procedure UnitAyudaClick(Sender: TObject); procedure UnitVisualizacionClick(Sender: TObject); private { Private declarations } public procedure llenarCombo; { Public declarations } end; var FormListas: TFormListas; primeroS,actualS, nuevoS,ultimoS: nodoS; primeroD,actualD, nuevoD,ultimoD: nodoD; primeroC,actualC, nuevoC,ultimoC: nodoC; bandera,ban,mensaje,ord,banBaja, cantidad:integer; codigo:string; existe,focus:boolean; implementation uses UAyuda, UClave, UVer; {$R *.DFM} procedure TFormListas.FormActivate(Sender: TObject); begin ban:=0; banBaja:=0; bandera:=2; end;
Si tenes ganas de estudiar, sentate hasta que se te pase..!!!
CARGANDO NUEVOS NODOS
En los siguientes renglones podrás ver la manera como se maneja el proceso de carga de los campos de cada nodo y como se direccionan los punteros para generar las listas enlazadas dinámicamente.
procedure TFormListas.Altas1Click(Sender: TObject); begin LabelTitulo.Caption:='Ingreso de Datos de CDs'; PanelAltas.Visible:=true; BoxCodigo.SetFocus; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; bandera:=1; end; procedure TFormListas.Altas2Click(Sender: TObject); begin LabelTitulo.Caption:='Ingreso de Datos de CDs'; PanelAltas.Visible:=true; BoxCodigo.SetFocus; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; bandera:=2; end; procedure TFormListas.Altas3Click(Sender: TObject); begin LabelTitulo.Caption:='Ingreso de Datos de CDs'; PanelAltas.Visible:=true; BoxCodigo.SetFocus; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; bandera:=3; end; function TFormListas.BuscarCod(cod:String ) :boolean; begin result:=false; case bandera of 1: begin actualS:=primeroS; if (actualS<>nil) then while (actualS <>nil)do begin if (StrToInt(cod) = actualS^.codigo) then begin result:=true;//Indica que el código ingresado existe exit; end; actualS:=actualS^.siguiente; end; end; 2: begin actualD:=primeroD; if (actualD<>nil) then while (actualD <>nil)do begin if (StrToInt(cod) = actualD^.codigo) then begin result:=true;//Indica que el código ingresado existe exit; end; actualD:=actualD^.siguiente; end; end; 3: begin actualC:=primeroC; if (primeroC=nil) then begin result:=false; exit; end; while (actualC^.siguiente <>primeroC)do begin if (StrToInt(cod) = actualC^.codigo) then begin result:=true;//Indica que el código ingresado existe exit; end; actualC:=actualC^.siguiente; end; if (StrToInt(cod) = actualC^.codigo) then result:=true; exit; end; end; end; procedure TFormListas.Salir1Click(Sender: TObject); begin FormClave.close; end; procedure TFormListas.FormClose(Sender: TObject; var Action: TCloseAction); begin FormClave.Close; end; procedure TFormListas.BLimpiarClick(Sender: TObject); begin BoxCodigo.Enabled:=true; BoxNombre.Enabled:=true; BoxCantante.Enabled:=true; BoxPreCosto.Enabled:=true; BoxPreVenta.Enabled:=true; BoxCantidad.Enabled:=true; BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; BGrabar.Enabled:=true; end; procedure TFormListas.BSalirAltasClick(Sender: TObject); begin PanelAltas.Visible:=false; BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.Enabled:=true; BoxNombre.Enabled:=true; BoxCantante.Enabled:=true; BoxPreCosto.Enabled:=true; BoxPreVenta.Enabled:=true; BoxCantidad.Enabled:=true; BGrabar.Enabled:=true; ComboCodigo.Visible:=false; BGrabar.Visible:=true; BModificar.Visible:=false; BEliminar.Visible:=false; BoxCodigo.Visible:=true; BLimpiar.Enabled:=true; ListaSimple.Enabled:=true; ListaDoble.Enabled:=true; ListaCircular.Enabled:=true; banBaja:=0; end; procedure TFormListas.llenarCombo; begin FormListas.ComboCodigo.Items.Clear; FormListas.ComboCodigo.Clear; FormVer.ComboCodigo.Items.Clear; FormVer.ComboCodigo.Clear; case bandera of 1: begin actualS:=primeroS; while(actualS <> nil)do begin FormListas.ComboCodigo.Items.Add(IntToStr(actualS^.codigo)); FormVer.ComboCodigo.Items.Add(IntToStr(actualS^.codigo)); actualS:=actualS^.siguiente; end; end; 2: begin actualD:=primeroD; while(actualD <> nil)do begin FormListas.ComboCodigo.Items.Add(IntToStr(actualD^.codigo)); FormVer.ComboCodigo.Items.Add(IntToStr(actualD^.codigo)); actualD:=actualD^.siguiente; end; end; 3: begin actualC:=primeroC; while(actualC^.siguiente <> primeroC)do begin FormListas.ComboCodigo.Items.Add(IntToStr(actualC^.codigo)); FormVer.ComboCodigo.Items.Add(IntToStr(actualC^.codigo)); actualC:=actualC^.siguiente; end; FormListas.ComboCodigo.Items.Add(IntToStr(actualC^.codigo)); FormVer.ComboCodigo.Items.Add(IntToStr(actualC^.codigo)); end; end; end; procedure TFormListas.BGrabarClick(Sender: TObject); begin if ((BoxCodigo.Text='')or (BoxNombre.Text='')or (BoxCantidad.Text=''))then Application.MessageBox('Verifique si están completos los campos de Código,Nombre o Cantidad', 'Faltan Datos!!!',mb_iconinformation) else begin case bandera of 1: begin codigo:=BoxCodigo.Text; if not BuscarCod(codigo) then begin new(nuevoS); nuevoS^.codigo:=StrToInt(BoxCodigo.Text); nuevoS^.nombre:=UpperCase(BoxNombre.Text); nuevoS^.cantante:=UpperCase(BoxCantante.Text); nuevoS^.preCosto:=BoxPreCosto.Text; nuevoS^.preVenta:=BoxPreVenta.Text; nuevoS^.cantidad:=StrToInt(BoxCantidad.Text); nuevoS^.siguiente:=nil; ultimoS:=nuevoS; if (primeroS=nil)then primeroS:=nuevoS else begin actualS:=primeroS; while (actualS^.siguiente <> nil)do actualS:=actualS^.siguiente; actualS^.siguiente:=nuevoS; end; llenarCombo; BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; end else begin mensaje:=Application.MessageBox('¿Desea ampliar el stock de éste producto?','Código Ya Existente!',MB_ICONQUESTION+MB_OKCANCEL+MB_DEFBUTTON1); if (mensaje=IDOK)then begin BoxCodigo.Enabled:=false; BoxNombre.Enabled:=false; BoxCantante.Enabled:=false; BoxPreCosto.Enabled:=false; BoxPreVenta.Enabled:=false; BoxCantidad.Enabled:=false; BoxNombre.Text:=actualS^.nombre; BoxCantante.Text:=actualS^.cantante; BoxPreCosto.Text:=actualS^.preCosto; BoxPreVenta.Text:=actualS^.preVenta; BoxCantidad.Text:=IntToStr(actualS^.cantidad); PanelCantidad.Visible:=true; BoxCantidad2.SetFocus; PanelAltas.Enabled:=false; end else begin BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; end; end; end; 2: begin codigo:=BoxCodigo.Text; existe:=BuscarCod(codigo); if (existe=false)then begin nuevoD:= new(nodoD); nuevoD^.codigo:=StrToInt(BoxCodigo.Text); nuevoD^.nombre:=UpperCase(BoxNombre.Text); nuevoD^.cantante:=UpperCase(BoxCantante.Text); nuevoD^.preCosto:=BoxPreCosto.Text; nuevoD^.preVenta:=BoxPreVenta.Text; nuevoD^.cantidad:=StrToInt(BoxCantidad.Text); nuevoD^.siguiente:=nil; nuevoD^.anterior:=nil; ultimoD:=nuevoD; if (primeroD=nil)then primeroD:=nuevoD else begin actualD:=primeroD; while (actualD^.siguiente <> nil)do actualD:=actualD^.siguiente; actualD^.siguiente:=nuevoD; nuevoD^.anterior:=actualD; //nuevoD^.siguiente:=nil; end; llenarCombo; BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; end else begin mensaje:=Application.MessageBox('¿Desea ampliar el stock de éste producto?','Código Ya Existente!',MB_ICONQUESTION+MB_OKCANCEL+MB_DEFBUTTON1); if (mensaje=IDOK)then begin BoxCodigo.Enabled:=false; BoxNombre.Enabled:=false; BoxCantante.Enabled:=false; BoxPreCosto.Enabled:=false; BoxPreVenta.Enabled:=false; BoxCantidad.Enabled:=false; BoxNombre.Text:=actualD^.nombre; BoxCantante.Text:=actualD^.cantante; BoxPreCosto.Text:=actualD^.preCosto; BoxPreVenta.Text:=actualD^.preVenta; BoxCantidad.Text:=IntToStr(actualD^.cantidad); PanelCantidad.Visible:=true; BoxCantidad2.SetFocus; end else begin BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; end; end; end; 3: begin codigo:=BoxCodigo.Text; existe:=BuscarCod(codigo); if (existe=false)then begin nuevoC:= new(nodoC); nuevoC^.codigo:=StrToInt(BoxCodigo.Text); nuevoC^.nombre:=UpperCase(BoxNombre.Text); nuevoC^.cantante:=UpperCase(BoxCantante.Text); nuevoC^.preCosto:=BoxPreCosto.Text; nuevoC^.preVenta:=BoxPreVenta.Text; nuevoC^.cantidad:=StrToInt(BoxCantidad.Text); nuevoC^.siguiente:=nil; nuevoC^.anterior:=nil; ultimoC:=nuevoC; if (primeroC=nil)then begin primeroC:=nuevoC; primeroC^.siguiente:=nuevoC; primeroC^.anterior:=nuevoC; end else begin actualC:=primeroC; while (actualC^.siguiente <> primeroC)do actualC:=actualC^.siguiente; actualC^.siguiente:=nuevoC; nuevoC^.anterior:=actualC; nuevoC^.siguiente:=primeroC; primeroC^.anterior:=nuevoC; end; llenarCombo; BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; end else begin mensaje:=Application.MessageBox('¿Desea ampliar el stock de éste producto?','Código Ya Existente!',MB_ICONQUESTION+MB_OKCANCEL+MB_DEFBUTTON1); if (mensaje=IDOK)then begin BoxCodigo.Enabled:=false; BoxNombre.Enabled:=false; BoxCantante.Enabled:=false; BoxPreCosto.Enabled:=false; BoxPreVenta.Enabled:=false; BoxCantidad.Enabled:=false; BoxNombre.Text:=actualC^.nombre; BoxCantante.Text:=actualC^.cantante; BoxPreCosto.Text:=actualC^.preCosto; BoxPreVenta.Text:=actualC^.preVenta; BoxCantidad.Text:=IntToStr(actualC^.cantidad); PanelCantidad.Visible:=true; BoxCantidad2.SetFocus; end else begin BoxCodigo.Clear; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxCodigo.SetFocus; end; end; end; end; end; end;
El amor como la gripe siempre terminan en la cama..!!!
VIENDO EL CONTENIDO DE LOS NODOS
En este sector te recomiendo comprender los procedimientos de transferencia de los datos de los nodos a los objetos de visualización.
procedure TFormListas.BOkClick(Sender: TObject); begin case (bandera)of 1: begin actualS^.cantidad:=StrToInt(BoxCantidad2.Text) + actualS^.cantidad; cantidad:=actualS^.cantidad; end; 2: begin actualD^.cantidad:=StrToInt(BoxCantidad2.Text) + actualD^.cantidad; cantidad:=actualD^.cantidad; end; 3: begin actualC^.cantidad:=StrToInt(BoxCantidad2.Text) + actualC^.cantidad; cantidad:=actualC^.cantidad; end; end; BoxCantidad.Text:=IntToStr(cantidad); BoxCantidad2.Clear; PanelCantidad.Visible:=false; BGrabar.Enabled:=false; PanelAltas.Enabled:=true; end; procedure TFormListas.ordenarSimple(ord: integer); var cod, cant:integer; nom,can,precos,preven:string; aux:nodoS ; begin bandera:=1; actualS:=primeroS; while (actualS^.siguiente <> nil)do begin aux:=actualS^.siguiente; while (aux <> nil)do begin if (ord=0)then//Indica ordenamiento por c¢digo begin if (actualS.codigo > aux.codigo) then begin cod:=actualS^.codigo; nom:=actualS^.nombre; can:=actualS^.cantante; precos:=actualS^.preCosto; preven:=actualS^.preVenta; cant:=actualS^.cantidad; actualS^.codigo:=aux^.codigo; actualS^.nombre:=aux^.nombre; actualS^.cantante:=aux^.cantante; actualS^.preCosto:=aux^.preCosto; actualS^.preVenta:=aux^.preVenta; actualS^.cantidad:=aux^.cantidad; aux^.codigo:=cod; aux^.nombre:=nom; aux^.cantante:=can; aux^.preCosto:=precos; aux^.preVenta:=preven; aux^.cantidad:=cant; end; end else if (actualS^.nombre > aux^.nombre)then begin cod:=actualS^.codigo; nom:=actualS^.nombre; can:=actualS^.cantante; precos:=actualS^.preCosto; preven:=actualS^.preVenta; cant:=actualS^.cantidad; actualS^.codigo:=aux^.codigo; actualS^.nombre:=aux^.nombre; actualS^.cantante:=aux^.cantante; actualS^.preCosto:=aux^.preCosto; actualS^.preVenta:=aux^.preVenta; actualS^.cantidad:=aux^.cantidad; aux^.codigo:=cod; aux^.nombre:=nom; aux^.cantante:=can; aux^.preCosto:=precos; aux^.preVenta:=preven; aux^.cantidad:=cant; end; aux:=aux^.siguiente; end; actualS:=actualS^.siguiente; end; llenarCombo; if (ord=0)then Application.MessageBox('La Lista está ordenada por CODIGO','',MB_ICONEXCLAMATION+MB_OK) else Application.MessageBox('La Lista está ordenada por NOMBRE','',MB_ICONEXCLAMATION+MB_OK); end; procedure TFormListas.ordenarDoble(ord: integer); var cod, cant:integer; nom,can,precos,preven:string; aux:nodoD ; begin bandera:=2; actualD:=primeroD; while (actualD^.siguiente <> nil)do begin aux:=actualD^.siguiente; while (aux <>nil)do begin if (ord=0)then//Indica ordenamiento por c¢digo begin if (actualD^.codigo > aux^.codigo)then begin cod:=actualD^.codigo; nom:=actualD^.nombre; can:=actualD^.cantante; precos:=actualD^.preCosto; preven:=actualD^.preVenta; cant:=actualD^.cantidad; actualD^.codigo:=aux^.codigo; actualD^.nombre:=aux^.nombre; actualD^.cantante:=aux^.cantante; actualD^.preCosto:=aux^.preCosto; actualD^.preVenta:=aux^.preVenta; actualD^.cantidad:=aux^.cantidad; aux^.codigo:=cod; aux^.nombre:=nom; aux^.cantante:=can; aux^.preCosto:=precos; aux^.preVenta:=preven; aux^.cantidad:=cant; end; end else if (actualD^.nombre > aux^.nombre) then begin cod:=actualD^.codigo; nom:=actualD^.nombre; can:=actualD^.cantante; precos:=actualD^.preCosto; preven:=actualD^.preVenta; cant:=actualD^.cantidad; actualD^.codigo:=aux^.codigo; actualD^.nombre:=aux^.nombre; actualD^.cantante:=aux^.cantante; actualD^.preCosto:=aux^.preCosto; actualD^.preVenta:=aux^.preVenta; actualD^.cantidad:=aux^.cantidad; aux^.codigo:=cod; aux^.nombre:=nom; aux^.cantante:=can; aux^.preCosto:=precos; aux^.preVenta:=preven; aux^.cantidad:=cant; end; aux:=aux^.siguiente; end; actualD:=actualD^.siguiente; end; llenarCombo; if (ord=0)then Application.MessageBox('La Lista está ordenada por CODIGO','',MB_ICONEXCLAMATION+MB_OK) else Application.MessageBox('La Lista está ordenada por NOMBRE','',MB_ICONEXCLAMATION+MB_OK); end; procedure TFormListas.ordenarCircular(ord: integer); var cod, cant:integer; nom,can,precos,preven:string; aux:nodoC ; begin bandera:=3; actualC:=primeroC; while (actualC^.siguiente <> primeroC)do begin aux:=actualC^.siguiente; while (aux <> primeroC)do begin if (ord=0)then//Indica ordenamiento por c¢digo begin if (actualC^.codigo > aux^.codigo)then begin cod:=actualC^.codigo; nom:=actualC^.nombre; can:=actualC^.cantante; precos:=actualC^.preCosto; preven:=actualC^.preVenta; cant:=actualC^.cantidad; actualC^.codigo:=aux^.codigo; actualC^.nombre:=aux^.nombre; actualC^.cantante:=aux^.cantante; actualC^.preCosto:=aux^.preCosto; actualC^.preVenta:=aux^.preVenta; actualC^.cantidad:=aux^.cantidad; aux^.codigo:=cod; aux^.nombre:=nom; aux^.cantante:=can; aux^.preCosto:=precos; aux^.preVenta:=preven; aux^.cantidad:=cant; end; end else if (actualC^.nombre > aux^.nombre)then begin cod:=actualC^.codigo; nom:=actualC^.nombre; can:=actualC^.cantante; precos:=actualC^.preCosto; preven:=actualC^.preVenta; cant:=actualC^.cantidad; actualC^.codigo:=aux^.codigo; actualC^.nombre:=aux^.nombre; actualC^.cantante:=aux^.cantante; actualC^.preCosto:=aux^.preCosto; actualC^.preVenta:=aux^.preVenta; actualC^.cantidad:=aux^.cantidad; aux^.codigo:=cod; aux^.nombre:=nom; aux^.cantante:=can; aux^.preCosto:=precos; aux^.preVenta:=preven; aux^.cantidad:=cant; end; aux:=aux^.siguiente; end; actualC:=actualC^.siguiente; end; llenarCombo; if (ord=0)then Application.MessageBox('La Lista está ordenada por CODIGO','',MB_ICONEXCLAMATION+MB_OK) else Application.MessageBox('La Lista está ordenada por NOMBRE','',MB_ICONEXCLAMATION+MB_OK); end; procedure TFormListas.PorCodigo1Click(Sender: TObject); begin if (primeroS <> nil) then begin ord:=0; ordenarSimple(ord); end else Application.MessageBox('No hay datos para ordenar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.PorNombre1Click(Sender: TObject); begin if (primeroS <> nil)then begin ord:=1; ordenarSimple(ord); end else Application.MessageBox('No hay datos para ordenar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.PorCodigo2Click(Sender: TObject); begin if (primeroD <> nil)then begin ord:=0; ordenarDoble(ord); end else Application.MessageBox('No hay datos para ordenar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.PorNombre2Click(Sender: TObject); begin if (primeroD <> nil)then begin ord:=1; ordenarDoble(ord); end else Application.MessageBox('No hay datos para ordenar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.PorCodigo3Click(Sender: TObject); begin if (primeroC <> nil)then begin ord:=0; ordenarCircular(ord); end else Application.MessageBox('No hay datos para ordenar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.PorNombre3Click(Sender: TObject); begin if (primeroC <> nil)then begin ord:=1; ordenarCircular(ord); end else Application.MessageBox('No hay datos para ordenar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end;
Qué cuentan las ovejas para poder dormir..!!!
CAMBIAR EL CONTENIDO DE LOS NODOS
En los siguientes renglones te recomiendo captar los mecanismos de ubicación del nodo a modificar y la forma de actuar el puntero direccionado al campo llave.
procedure TFormListas.Modificaciones1Click(Sender: TObject); begin LabelTitulo.Caption:='Modificación de Datos'; if (primeroS <> nil)then begin bandera:=1; PanelAltas.Visible:=true; BoxCodigo.Visible:=false; ComboCodigo.Visible:=true; BGrabar.Visible:=false; BModificar.Visible:=true; BLimpiar.Enabled:=false; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; llenarCombo; end else Application.MessageBox('No hay datos para Modificar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Modificaciones2Click(Sender: TObject); begin LabelTitulo.Caption:='Modificación de Datos'; if (primeroD <> nil)then begin bandera:=2; PanelAltas.Visible:=true; BoxCodigo.Visible:=false; ComboCodigo.Visible:=true; BGrabar.Visible:=false; BModificar.Visible:=true; BLimpiar.Enabled:=false; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; llenarCombo; end else Application.MessageBox('No hay datos para Modificar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Modificaciones3Click(Sender: TObject); begin LabelTitulo.Caption:='Modificación de Datos'; if (primeroC <> nil)then begin bandera:=3; PanelAltas.Visible:=true; BoxCodigo.Visible:=false; ComboCodigo.Visible:=true; BGrabar.Visible:=false; BModificar.Visible:=true; BLimpiar.Enabled:=false; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; llenarCombo; end else Application.MessageBox('No hay datos para Modificar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.BModificarClick(Sender: TObject); begin case bandera of 1: begin actualS^.nombre:=UpperCase(BoxNombre.Text); actualS^.cantante:=UpperCase(BoxCantante.Text); actualS^.preCosto:=BoxPreCosto.Text; actualS^.preVenta:=BoxPreVenta.Text; actualS^.cantidad:=StrToInt(BoxCantidad.Text); end; 2: begin actualD^.nombre:=UpperCase(BoxNombre.Text); actualD^.cantante:=UpperCase(BoxCantante.Text); actualD^.preCosto:=BoxPreCosto.Text; actualD^.preVenta:=BoxPreVenta.Text; actualD^.cantidad:=StrToInt(BoxCantidad.Text); end; 3: begin actualC^.nombre:=UpperCase(BoxNombre.Text); actualC^.cantante:=UpperCase(BoxCantante.Text); actualC^.preCosto:=BoxPreCosto.Text; actualC^.preVenta:=BoxPreVenta.Text; actualC^.cantidad:=StrToInt(BoxCantidad.Text); end; end; Application.MessageBox('Los datos ya han sido modificados','Modificación de Datos',MB_ICONINFORMATION+MB_OK); BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; BoxNombre.SetFocus; end;
Me las pagarán..!!! ( FMI )
BORRAR NODOS CON DATOS
En estos algoritmos te conviene captar los conceptos de baja lógica y baja física
procedure TFormListas.Bajas1Click(Sender: TObject); begin LabelTitulo.Caption:='Eliminación de Datos'; if (primeroS <> nil)then begin bandera:=1; PanelAltas.Visible:=true; BoxCodigo.Visible:=false; ComboCodigo.Visible:=true; BGrabar.Visible:=false; BModificar.Visible:=false; BEliminar.Visible:=true; BLimpiar.Enabled:=false; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; banBaja:=1; llenarCombo; end else Application.MessageBox('No hay datos para Eliminar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Bajas2Click(Sender: TObject); begin LabelTitulo.Caption:='Eliminación de Datos'; if (primeroD <> nil)then begin bandera:=2; PanelAltas.Visible:=true; BoxCodigo.Visible:=false; ComboCodigo.Visible:=true; BGrabar.Visible:=false; BModificar.Visible:=false; BEliminar.Visible:=true; BLimpiar.Enabled:=false; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; banBaja:=1; llenarCombo; end else Application.MessageBox('No hay datos para Eliminar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Bajas3Click(Sender: TObject); begin LabelTitulo.Caption:='Eliminación de Datos'; if (primeroC <> nil)then begin bandera:=3; PanelAltas.Visible:=true; BoxCodigo.Visible:=false; ComboCodigo.Visible:=true; BGrabar.Visible:=false; BModificar.Visible:=false; BEliminar.Visible:=true; BLimpiar.Enabled:=false; ListaSimple.Enabled:=false; ListaDoble.Enabled:=false; ListaCircular.Enabled:=false; banBaja:=1; llenarCombo; end else Application.MessageBox('No hay datos para Eliminar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.BEliminarClick(Sender: TObject); var auxS,aux1S:nodoS; auxD,aux1D:nodoD; auxC,auxC1:nodoC; begin case bandera of 1: begin if (primeroS <> nil)then begin mensaje:=Application.MessageBox('Deseas eliminar estos datos?','Eliminación de Datos',MB_ICONQUESTION+MB_OKCANCEL+MB_DEFBUTTON1); if (mensaje = IDOK)then begin auxS:=actualS; if (actualS = primeroS)then primeroS:=actualS^.siguiente else begin actualS:=primeroS; while(actualS^.siguiente <> nil) do begin if (actualS^.siguiente = auxS) then begin aux1S:=actualS; break; end; actualS:=actualS^.siguiente; end; aux1S^.siguiente:=auxS^.siguiente; end; dispose(auxS); llenarCombo; Application.MessageBox('Los datos ya han sido eliminados','Eliminación de Datos',MB_ICONINFORMATION+MB_OK); end; end else Application.MessageBox('No hay datos para Eliminar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; 2: begin if (primeroD <> nil)then begin mensaje:=Application.MessageBox('Deseas eliminar estos datos?','Eliminación de Datos',MB_ICONQUESTION+MB_OKCANCEL+MB_DEFBUTTON1); if (mensaje = IDOK)then begin if (primeroD^.siguiente = nil) then primeroD:=nil else begin if(actualD = primeroD)then begin primeroD:=actualD^.siguiente; primeroD^.anterior:=nil; end else begin if (actualD^.siguiente=nil) then begin auxD:=actualD^.anterior; auxD^.siguiente:=nil; end else begin auxD:=actualD^.anterior; auxD^.siguiente:=actualD^.siguiente; aux1D:=actualD^.siguiente; aux1D^.anterior:=auxD; end; end; end; dispose(actualD); llenarCombo; Application.MessageBox('Los datos ya han sido eliminados','Eliminación de Datos',MB_ICONINFORMATION+MB_OK); end; end else Application.MessageBox('No hay datos para Eliminar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; 3: begin if (primeroC <> nil )then begin mensaje:=Application.MessageBox('Deseas eliminar estos datos?','Eliminación de Datos',MB_ICONQUESTION+MB_OKCANCEL+MB_DEFBUTTON1); if (mensaje = IDOK)then begin if (primeroC^.siguiente=primeroC)then begin primeroC:=nil; FormListas.ComboCodigo.Items.Clear; FormListas.ComboCodigo.Clear; FormVer.ComboCodigo.Items.Clear; FormVer.ComboCodigo.Clear; end else begin auxC:=actualC^.anterior; auxC1:=actualC^.siguiente; auxC^.siguiente:=auxC1; auxC1^.anterior:=auxC; if (actualC = primeroC)then primeroC:=auxC1; dispose(actualC); llenarCombo; end; Application.MessageBox('Los datos ya han sido eliminados','Eliminación de Datos',MB_ICONINFORMATION+MB_OK); end; end else Application.MessageBox('No hay datos para Eliminar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; end; BoxNombre.Clear; BoxCantante.Clear; BoxPreCosto.Clear; BoxPreVenta.Clear; BoxCantidad.Clear; end; procedure TFormListas.ComboCodigoChange(Sender: TObject); begin codigo:=ComboCodigo.Text; case bandera of 1: begin BuscarCod(codigo); BoxNombre.Text:=actualS^.nombre; BoxCantante.Text:=actualS^.cantante; BoxPreCosto.Text:=actualS^.preCosto; BoxPreVenta.Text:=actualS^.preVenta; BoxCantidad.Text:=IntToStr(actualS^.cantidad); end; 2: begin BuscarCod(codigo); BoxNombre.Text:=actualD^.nombre; BoxCantante.Text:=actualD^.cantante; BoxPreCosto.Text:=actualD^.preCosto; BoxPreVenta.Text:=actualD^.preVenta; BoxCantidad.Text:=IntToStr(actualD^.cantidad); end; 3: begin BuscarCod(codigo); BoxNombre.Text:=actualC^.nombre; BoxCantante.Text:=actualC^.cantante; BoxPreCosto.Text:=actualC^.preCosto; BoxPreVenta.Text:=actualC^.preVenta; BoxCantidad.Text:=IntToStr(actualC^.cantidad); end; end; if (banBaja = 1)then begin BoxNombre.Enabled:=false; BoxCantante.Enabled:=false; BoxPreCosto.Enabled:=false; BoxPreVenta.Enabled:=false; BoxCantidad.Enabled:=false; BEliminar.SetFocus; end else BModificar.SetFocus; end;
Soy un quemo..!!! ( Nerón )
ALGORITMOS COMPLEMENTARIOS
Este sector te propone un conjunto de procedimientos de uso común en una gran mayoría de aplicaciones codificados en Delphi y que por lo tanto puedes ajustarlos a tus propias necesidades.
Buena suerte..!!!
procedure TFormListas.Listado1Click(Sender: TObject); begin if (primeroS<>nil)then begin FormListas.Hide; FormVer.Show; end else Application.MessageBox('No hay datos para Visualizar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Listado2Click(Sender: TObject); begin if (primeroD<>nil)then begin FormListas.Hide; FormVer.Show; end else Application.MessageBox('No hay datos para Visualizar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Listado3Click(Sender: TObject); begin if (primeroC<>nil)then begin FormListas.Hide; FormVer.Show; end else Application.MessageBox('No hay datos para Visualizar','Lista Vacía',MB_ICONINFORMATION+MB_OK); end; procedure TFormListas.Acercade1Click(Sender: TObject); begin FormAyuda.Show; FormListas.Hide; FormAyuda.PanelAcerca.Visible:=true; FormAyuda.Caption:=' Acerca del Programa'; end; procedure TFormListas.AutorClick(Sender: TObject); begin FormAyuda.PanelAutoras.Visible:=true; FormAyuda.Show; FormListas.Hide; FormAyuda.Caption:=' AUTOR DEL PROGRAMA'; end; procedure TFormListas.BoxNombreKeyPress(Sender: TObject; var Key: Char); begin if (Key = #13)then BoxCantante.SetFocus; end; procedure TFormListas.BoxCantanteKeyPress(Sender: TObject; var Key: Char); begin if (Key = #13)then BoxPreCosto.SetFocus; end; procedure TFormListas.BoxPreCostoKeyPress(Sender: TObject; var Key: Char); begin if (Key =#13)then begin focus:=false; Validar(BoxPreCosto.Text); if (focus = false)then BoxPreVenta.SetFocus else begin mensaje:= Application.MessageBox('El Precio de costo debe ser numérico!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxPreCosto.SetFocus; BoxPreCosto.Clear; end; end; end; procedure TFormListas.BoxPreVentaKeyPress(Sender: TObject; var Key: Char); begin if (Key =#13)then begin focus:=false; Validar(BoxPreVenta.Text); if (focus = false)then BoxCantidad.SetFocus else begin mensaje:= Application.MessageBox('El Precio de Venta debe ser numérico!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxPreVenta.SetFocus; BoxPreVenta.Clear; end; end; end; procedure TFormListas.BoxCantidadKeyPress(Sender: TObject; var Key: Char); begin if (Key =#13)then begin focus:=false; Validar(BoxCantidad.Text); if (focus = false)then BGrabar.SetFocus else begin mensaje:= Application.MessageBox('La cantidad debe ser numérica!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxCantidad.SetFocus; BoxCantidad.Clear; end; end; end; procedure TFormListas.BoxCodigoKeyPress(Sender: TObject; var Key: Char); begin if (Key =#13)then begin focus:=false; Validar(BoxCodigo.Text); if (focus = false)then BoxNombre.SetFocus else begin mensaje:= Application.MessageBox('El Código debe ser numérico!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxCodigo.SetFocus; BoxCodigo.Clear; end; end; end; procedure TFormListas.BoxCantidad2KeyPress(Sender: TObject; var Key: Char); begin if (Key =#13)then begin focus:=false; Validar(BoxCantidad2.Text); if (focus = false)then BOk.SetFocus else begin mensaje:= Application.MessageBox('La Cantidad debe ser numérica!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxCantidad2.SetFocus; BoxCantidad2.Clear; end; end; end; procedure TFormListas.ListaSimple2Click(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='Lista Simple'; FormAyuda.MemoSimple.Visible:=true; FormAyuda.Caption:=' Teoría de Lista Simple'; end; procedure TFormListas.ListaDoble2Click(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='Lista Doble'; FormAyuda.MemoDoble.Visible:=true; FormAyuda.Caption:=' Teoría de Lista Doble'; end; procedure TFormListas.ListaCircular2Click(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='Lista Circular'; FormAyuda.MemoCircular.Visible:=true; FormAyuda.Caption:=' Teoría de Lista Circular'; end; procedure TFormListas.Validar(num:string); var i:integer; begin for i:=1 to Length(num) do begin case num[i] of '0'..'9', ' ','.': continue else begin focus:= true; exit; end; end; end; end; procedure TFormListas.BoxCodigoExit(Sender: TObject); begin if (BoxCodigo.Text<>'')then begin focus:=false; Validar(BoxCodigo.Text); if (focus = false)then BoxNombre.SetFocus else begin mensaje:= Application.MessageBox('El Código debe ser numérico!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxCodigo.SetFocus; BoxCodigo.Clear; end; end else exit; end; procedure TFormListas.BoxPreCostoExit(Sender: TObject); begin focus:=false; Validar(BoxPreCosto.Text); if (focus = false)then BoxPreVenta.SetFocus else begin mensaje:= Application.MessageBox('El Precio de costo debe ser numérico!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxPreCosto.SetFocus; BoxPreCosto.Clear; end; end; procedure TFormListas.BoxPreVentaExit(Sender: TObject); begin focus:=false; Validar(BoxPreVenta.Text); if (focus = false)then BoxCantidad.SetFocus else begin mensaje:= Application.MessageBox('El Precio de Venta debe ser numérico!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxPreVenta.SetFocus; BoxPreVenta.Clear; end; end; procedure TFormListas.BoxCantidadExit(Sender: TObject); begin focus:=false; Validar(BoxCantidad.Text); if (focus = false)then BGrabar.SetFocus else begin mensaje:= Application.MessageBox('La cantidad debe ser numérica!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxCantidad.SetFocus; BoxCantidad.Clear; end; end; procedure TFormListas.BoxCantidad2Exit(Sender: TObject); begin focus:=false; Validar(BoxCantidad2.Text); if (focus = false)then BOk.SetFocus else begin mensaje:= Application.MessageBox('La Cantidad debe ser numérica!','Preste ATENCION...!!', mb_iconexclamation+mb_OK+mb_defbutton1); BoxCantidad2.SetFocus; BoxCantidad2.Clear; end; end; procedure TFormListas.UnitClaveClick(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='UNIT CLAVE'; FormAyuda.MemoClave.Visible:=true; FormAyuda.Caption:=' Codificación del programa'; end; procedure TFormListas.UnitPrincipalClick(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='UNIT PRINCIPAL'; FormAyuda.MemoPrincipal.Visible:=true; FormAyuda.Caption:=' Codificación del programa'; end; procedure TFormListas.UnitAyudaClick(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='UNIT AYUDA'; FormAyuda.MemoAyuda.Visible:=true; FormAyuda.Caption:=' Codificación del programa'; end; procedure TFormListas.UnitVisualizacionClick(Sender: TObject); begin FormListas.Hide; FormAyuda.Show; FormAyuda.PanelCodificacion.Visible:=true; FormAyuda.PanelCodificacion.Caption:='UNIT VER'; FormAyuda.MemoVer.Visible:=true; FormAyuda.Caption:=' Codificación del programa'; end; end.
Gracias Ana y Carolina..!!