Ver Mensaje Individual
  #3  
Antiguo 19-03-2012
ungrande87 ungrande87 is offline
Miembro
NULL
 
Registrado: feb 2012
Posts: 42
Reputación: 0
ungrande87 Va por buen camino
Cita:
Empezado por ecfisa Ver Mensaje
Hola ungrande87.

Te pongo un ejemplo simplificado de una forma en que podrías implementarlo:

Form1:

Código Delphi [-]
...

uses ..., Unit2;

type
TAccion = (acAdd, acUpd); // nuevo, modifica
TForm1 = class(TForm)
ListView1: TListView;
btNuevo: TButton;
btModifica: TButton;
btBorra: TButton;
procedure FormCreate(Sender: TObject);
procedure btNuevoClick(Sender: TObject);
procedure btModificaClick(Sender: TObject);
procedure btBorraClick(Sender: TObject);
private
FAccion: TAccion;
procedure ArticuloChange(Value: TArticulo);
public
end;
...

implementation

(* Recibe evento cambio en artículo *)
procedure TForm1.ArticuloChange(Value: TArticulo);
begin
case FAccion of
acAdd: with ListView1.Items.Add do // nuevo
begin
SubItems.Add(Articulo.Codigo);
SubItems.Add(Articulo.Nombre)
end;
acUpd: with ListView1.Items[ListView1.ItemIndex] do // modifica
begin
SubItems[0]:= Articulo.Codigo;
SubItems[1]:= Articulo.Nombre
end;
end;
end;

(* Valores iniciales *)
procedure TForm1.FormCreate(Sender: TObject);
var
Col: TListColumn;
begin
with ListView1 do
begin
ViewStyle:= vsReport;
ReadOnly:= True;
RowSelect:= True;
Col:= Columns.Add;
Col.Caption:= 'ID';
Col.Width:= 0; // (oculta, no la uso en el ejemplo)
Col:= Columns.Add;
Col.Caption:= 'CODIGO';
Col:= Columns.Add;
Col.Caption:= 'NOMBRE';
end;
end;

(* Nuevo artículo *)
procedure TForm1.btNuevoClick(Sender: TObject);
begin
FAccion:= acAdd; // nuevo
with TForm2.Create(Self) do
try
ArticuloOnChange:= ArticuloChange;
ShowModal;
finally
Free;
end;
end;

(* Modificar artículo *)
procedure TForm1.btModificaClick(Sender: TObject);
begin
FAccion:= acUpd; // modifica
with TForm2.Create(Self) do
try
ArticuloOnChange:= ArticuloChange;
ShowModal;
finally
Free;
end;
end;

(* Borrar artículo *)
procedure TForm1.btBorraClick(Sender: TObject);
begin
ListView1.Items[ListView1.ItemIndex].Delete;
end;
...





Form2:

Código Delphi [-]
type
TArticulo = record
Codigo: string;
Nombre: string;
end;

TCambioArticulo = procedure(Value: TArticulo) of object;
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
btAceptar: TButton;
procedure btAceptarClick(Sender: TObject);
private
FCambioArticulo: TCambioArticulo;
public
property ArticuloOnChange: TCambioArticulo read FCambioArticulo
write FCambioArticulo;
end;

...

implementation

procedure TForm2.btAceptarClick(Sender: TObject);
begin
if Assigned(FCambioArticulo) then
begin
Articulo.Codigo:= Edit1.Text;
Articulo.Nombre:= Edit2.Text;
FCambioArticulo(Articulo);
end;
Close;
end;
...




En el ejemplo actualiza en el evento OnClick del botón aceptar del segundo form.


Saludos.
Muchisimas gracias amigo, me super sirvio tu ejemplo.

Ahora una consulta mas, y si quisiera implementar en una nueva pantalla una consulta por: alfabeto o codigo descendiente por ejemplo, como tendria que hacer para que me filtre de ese modo el ListView, cargando datos en un Edit1?
Responder Con Cita