Cita:
Mi consulta es como debo manejar el TListView para cargar desde un formulario y que al cerrar o minimizar el mismo se actualice el la segunda pantalla al instante
|
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); 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
procedure TForm1.ArticuloChange(Value: TArticulo);
begin
case FAccion of
acAdd: with ListView1.Items.Add do begin
SubItems.Add(Articulo.Codigo);
SubItems.Add(Articulo.Nombre)
end;
acUpd: with ListView1.Items[ListView1.ItemIndex] do begin
SubItems[0]:= Articulo.Codigo;
SubItems[1]:= Articulo.Nombre
end;
end;
end;
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; Col:= Columns.Add;
Col.Caption:= 'CODIGO';
Col:= Columns.Add;
Col.Caption:= 'NOMBRE';
end;
end;
procedure TForm1.btNuevoClick(Sender: TObject);
begin
FAccion:= acAdd; with TForm2.Create(Self) do
try
ArticuloOnChange:= ArticuloChange;
ShowModal;
finally
Free;
end;
end;
procedure TForm1.btModificaClick(Sender: TObject);
begin
FAccion:= acUpd; with TForm2.Create(Self) do
try
ArticuloOnChange:= ArticuloChange;
ShowModal;
finally
Free;
end;
end;
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.