Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Actualizacion de un TDirectoryListBox a partir de un TDriveComboBox (https://www.clubdelphi.com/foros/showthread.php?t=64576)

GerTorresM 08-04-2009 02:17:31

Actualizacion de un TDirectoryListBox a partir de un TDriveComboBox
 
Estoy intentando construir en un formaularios dos objetos un TDriveComboBox que debe me muestra las unidades del equipo TDirectoryListBox que me muestra los ditrectorios de la unidad, el problema es que al cambiar la unidad no me refresca el listado los directorios de la unidad seleccionada, el codigo es el siguiente

Código Delphi [-]
unit UCopiaSeguridad;

interface

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

type
  TFCopiaSeguridad = class(TForm)
    procedure FormCreate(Sender: TObject);

  private
    { Private declarations }
    procedure crearCopiaSeguridad;
    procedure restaurarCopiaSeguridad;
    procedure crearUnidades (Pariente : TWinControl);
    procedure unidadesChange(Sender: TObject);
    procedure unidadesClick(Sender: TObject);
    procedure listaCarpetasChange(Sender: TObject);
    procedure crearDirectorio (Pariente : TWinControl);
  public
    { Public declarations }
    Unidades : TDriveComboBox;
    ListaCarpetas : TDirectoryListBox;
    Fichero : TStringList;
    Ruta : String;
  end;

var
  FCopiaSeguridad: TFCopiaSeguridad;

implementation

{$R *.dfm}

procedure TFCopiaSeguridad.FormCreate(Sender: TObject);
begin
  crearDirectorio(FCopiaSeguridad);
  crearUnidades(FCopiaSeguridad);
end;


procedure TFCopiaSeguridad.crearCopiaSeguridad();
begin
end;


procedure TFCopiaSeguridad.restaurarCopiaSeguridad();
begin
end;

procedure TFCopiaSeguridad.crearUnidades (Pariente : TWinControl);
begin
  with TDriveComboBox.Create(self) do
    begin
      parent:= Pariente;
      top:= 15;
      left:= 15;
      OnClick:= UnidadesClick;
      OnChange:= UnidadesChange;
      DirList:= ListaCarpetas;
    end;
  Unidades:= TDriveComboBox.Create(nil);
end;

procedure TFCopiaSeguridad.crearDirectorio (Pariente : TWinControl);
begin

  with TDirectoryListBox.Create(self) do
    begin
      parent:= Pariente;
      top:= 40;
      left:= 15;
      ItemHeight:= 16;
      TabOrder:= 1;
      OnChange:= ListaCarpetasChange;
    end;
  ListaCarpetas:= TDirectoryListBox.Create(nil);
end;

procedure TFCopiaSeguridad.UnidadesChange(Sender: TObject);
begin
  // ListaCarpetas.Drive:= Unidades.Drive;
end;

procedure TFCopiaSeguridad.UnidadesClick(Sender: TObject);
begin
  // ListaCarpetas.Drive:= Unidades.Drive;
  // ListaCarpetas.Refresh;
end;


procedure TFCopiaSeguridad.ListaCarpetasChange(Sender: TObject);
begin
  showmessage('3');
end;

end.

He probado cuanto he podido pero no he logrado nada, agradezco de antemano la ayuda



Gertorresm
Colombia

Neftali [Germán.Estévez] 08-04-2009 09:39:51

En la propiedad DirList del DriveComboBox coloca el DirectoryListBox.
Con eso debería bastar.;)

GerTorresM 08-04-2009 13:54:45

Muchas gracías por el tiempo dedica, pero en el procedimiento de crearUnidades ya esta sitada la linea de codigo para lo que me comentas, pero no lo esta haciendo, te pido el favor que copies el código y lo ejecutes para que te des cuenta que no lo esta haciendo, y la verdad no se que estoy haciendo mal.


Gertorresm
Colombia

Neftali [Germán.Estévez] 08-04-2009 14:19:43

Ahora me he fijado en los procedimientos de creación y la verdad es que son "un poco raros" :D:D.

Primero creas el objeto y asignas propiedades y luego lo vuelves a crear (Create). :confused:

Creo que en el segundo paso estás intentando asignar el objeto a la variable, pero al volver a llamar al create, lo que estás haciendo es crear uno nuevo y perder lo que has hecho anteriormente.

Código Delphi [-]

  // Creas el objeto y le asignas propiedades.
  with TDriveComboBox.Create(self) do
    begin
      parent:= Pariente;
      top:= 15;
      left:= 15;
      OnClick:= UnidadesClick;
      OnChange:= UnidadesChange;
      DirList:= ListaCarpetas;
    end;
  // pero esto no lo tienes asignado en ningun sitio


  // al volver a llamar al create en Unidades tienes el objeto, pero 
  // sin nada asignado
  Unidades:= TDriveComboBox.Create(nil);

Prueba con algo así:

Código Delphi [-]
procedure TFCopiaSeguridad.crearUnidades (Pariente : TWinControl);
begin

  Unidades:= TDriveComboBox.Create(Self);

  with Unidades do
    begin
      parent:= Pariente;
      top:= 15;
      left:= 15;
      OnClick:= UnidadesClick;
      OnChange:= UnidadesChange;
      DirList:= ListaCarpetas;
    end;
end;


procedure TFCopiaSeguridad.crearDirectorio (Pariente : TWinControl);
begin

  ListaCarpetas:= TDirectoryListBox.Create(Self);

  with ListaCarpetas do
    begin
      parent:= Pariente;
      top:= 40;
      left:= 15;
      ItemHeight:= 16;
      TabOrder:= 1;
      OnChange:= ListaCarpetasChange;
    end;

end;

Que no se si es lo que querías hacer.

GerTorresM 08-04-2009 16:19:06

Muchas
 
Muchicimas Gracías Neftali, te agradezco en serio la indicación que me diste no solo soluciono el problema, sino que me hizo entender algo que no había logrado comprender


GerTorresM
Colombia:eek:


La franja horaria es GMT +2. Ahora son las 23:21:00.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi