Ver Mensaje Individual
  #2  
Antiguo 19-03-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
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);  // 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.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 19-03-2012 a las 10:59:08.
Responder Con Cita