Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#5

AW: Get Drive Letter

  Alt 23. Okt 2011, 21:48
Ok, a new Version...
Delphi-Quellcode:
function GetDriveLetter(DriveIdx:byte):string;
var
  vDrivesSize: Cardinal;
  vDrives : array[0..128] of Char;
  vDrive : PChar;
  Drive:string;
  Index:byte;
begin
  if DriveIdx = 0 then
    Drive:=GetCurrentDir
  else begin
    vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives);
    if vDrivesSize <> 0 then begin
      Index:=0;
      vDrive := vDrives;
      while (vDrive^ <> #0) and (Index < DriveIdx) do begin
        Drive:=StrPas(vDrive);
        Inc(vDrive, SizeOf(vDrive));
        inc(Index);
      end;
    end;
  end;
  Result:=copy(Drive, 1, 1);
end;
... and 1 will give drive 'C' which normally gives drive 'D'
This, I can't unterstand. I think if index = 0 gives you the CurrentDir, why should index = 1 gives you D. Than, it is an other work like this:

Delphi-Quellcode:
function GetDriveLetter(DriveIdx:byte):string;
var
  vDrivesSize: Cardinal;
  vDrives : array[0..128] of Char;
  vDrive : PChar;
  Drive:string;
  Index:byte;
begin
  Drive:='';
  vDrivesSize := GetLogicalDriveStrings(SizeOf(vDrives), vDrives);
  if vDrivesSize <> 0 then begin
    Index:=0;
    vDrive := vDrives;
    while (vDrive^ <> #0) and (Index <= DriveIdx) do begin
      Drive:=StrPas(vDrive);
      Inc(vDrive, SizeOf(vDrive));
      inc(Index);
    end;
  end;
  Result:=copy(Drive, 1, 1);
end;
But this Code gives you no CurrentDir, it is an esay Drivelist.

Geändert von omata (23. Okt 2011 um 22:12 Uhr)
  Mit Zitat antworten Zitat