Ver Mensaje Individual
  #10  
Antiguo 09-02-2008
[egostar] egostar is offline
Registrado
 
Registrado: feb 2006
Posts: 6.572
Reputación: 27
egostar Va camino a la fama
Cita:
Empezado por ixMike Ver Mensaje
Eso explota porque al hacer ListBox1.Items:=Lista y después liberar Lista, al intentar al acceder a ListBox1.Items... Error Acces violation bla bla bla porque ya no existe, ¡lo he liberado!


Salu2.
Amigo ixMike, que quieres decir con intentar acceder a ListBox1.Items, si liberas Lista el ListBox1.Items ya cargo lo que tuviese Lista, asi que no veo donde este el error de acceso.

Prueba este código, funciona sin problemas y accedes al ListBox tantas veces quieras y Lista ya está "liberada".......

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Lista: TStrings;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Lista := TStringList.Create;
  with Lista do begin
    Add('This example uses A string List.');
    Add('It is the easiest way to add strings');
    Add('to a combobox''s list of strings.');
    Add('Always remember TStrings.Create method');
    Add('is abstract; So use TStringList.Create');
    Add('method instead.');
  end;
  Listbox1.Items := Lista;
  Lista.Free;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
  ShowMessage(ListBox1.Items.Strings[ListBox1.ItemIndex]);
end;

end.

Salud OS
__________________
"La forma de empezar es dejar de hablar y empezar a hacerlo." - Walt Disney
Responder Con Cita