Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   error : has no parent windows (https://www.clubdelphi.com/foros/showthread.php?t=21627)

jorodgar 23-05-2005 20:44:28

error : has no parent windows
 
Tengo una unidad y un formulario principal.
En la unidad tengo el siguiente codigo :

function TNetDrive.FreeDriveName: string;
var
l : TStringList;
d : TDriveComboBox;
t : char;
i : integer;
begin
l:=TStringList.Create;
d:=TDriveComboBox.Create(self);
d.Parent:=Application.MainForm;
d.Visible:=false;
l.Assign(d.Items);
d.Free;
......
El error lo tengo en la linea d.Parent:=Application.MainForm; ya que si esa función me la pongo en el form principal y pongo d.Parent:=self, la cosa funciona perfectamente. ¿que está pasando ? :(

maeyanes 23-05-2005 20:54:56

Si no piensas mostrar el TDriveComboBox, no veo la necesidad de asignarle el valor a la propiedad Parent.

Otra cosa, para obtener la lista de los drivers de una PC, mejor checa el código fuente del TDriveComboBox, el método se llama TDriveComboBox.BuildList.


Saludos...

jorodgar 23-05-2005 21:11:41

si no pongo el parent me da el error que os puse.
Lo que deseo es cargar en un TStringList las unidades que tengo (a:, c:, ...)

La idea que me distes de usar BuildList, la verdad es que ando un poco perdido y no sé como utilizarlo. Seguiré buscando ...Gracias por tu aportación.

maeyanes 23-05-2005 21:24:44

Es solo hacerle algunas modificaciones al código para adaptarlo a lo que necesitas, por ejemplo:

Código Delphi [-]
procedure TNetDrive.GetDriversList(StrList: TStringList);
var
  DriveNum: Integer;
  DriveChar: Char;
  DriveType: TDriveType;
  DriveBits: set of 0..25;

  procedure AddDrive(const VolName: string);
  begin
    StrList.Add(Format('%s: %s', [DriveChar, VolName]))
  end;

begin
  StrList.Clear;
  Integer(DriveBits) := GetLogicalDrives;
  for DriveNum := 0 to 25 do
  begin
    if not (DriveNum in DriveBits) then
      Continue;
    DriveChar := Char(DriveNum + Ord('a'));
    DriveType := TDriveType(GetDriveType(PChar(DriveChar + ':\')));
    if TextCase = tcUpperCase then
      DriveChar := Upcase(DriveChar);
    case DriveType of
      dtFloppy:
        StrList.Add(DriveChar + ':');
      dtFixed:
        AddDrive(VolumeID(DriveChar));
      dtNetwork:
        AddDrive(NetworkVolume(DriveChar));
      dtCDROM:
        AddDrive(VolumeID(DriveChar));
      dtRAM:
        AddDrive(VolumeID(DriveChar))
    end
  end
end;

Así solo le pasas el StringList que quieres llenar con los drivers...


Saludos...

jorodgar 23-05-2005 21:27:53

ajá, entiendo lo que me quieres decir. Me pongo en ello y ya os cuento. Gracias. :)

jorodgar 23-05-2005 21:49:48

La modifique tal y como me dijistes a mis necesidades y funciona perfectamente. Es lo que deseaba. Muchiisimas gracias. :)

procedure TNetDrive.GetDriversList(StrList: TStringList);
var
DriveNum: Integer;
DriveChar: Char;
DriveBits: set of 0..25;
begin
StrList.Clear;
Integer(DriveBits) := GetLogicalDrives;
for DriveNum := 0 to 25 do
begin
if not (DriveNum in DriveBits) then
Continue;
DriveChar := Char(DriveNum + Ord('a'));
StrList.Add(DriveChar + ':');
end
end;


La franja horaria es GMT +2. Ahora son las 20:45:20.

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