Forum > Unix

list Windows drive Letters (compile on Linux)

<< < (2/4) > >>

Bart:
From one of my units:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function DiskInDrive(Drive: Char): Boolean;var  ErrorMode: word;begin  { maak er een hoofdletter van }  Drive := UpCase(Drive);  if not (Drive in ['A'..'Z']) then    raise EConvertError.Create('Geen geldige stationsaanduiding: '+Drive+':');  { schakel kritieke fouten uit }  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);  try    { drive 1 = a, 2 = b, 3 = c, etc. }    if DiskSize(Ord(Drive) - Ord('A') + 1) = -1 then      Result := False    else      Result := True;  finally    { restore old error mode }    SetErrorMode(ErrorMode);  end;end; function GetAvailableDrives(DiskMustBeInDrive: Boolean = False): TSysCharSet;var  D, Mask: DWORD;  C: Char;begin  Result := [];  D := GetLogicalDrives;  for C := 'A' to 'Z' do  begin    Mask := (1 shl (Ord(C) - Ord('A')));    if (Mask and D) = Mask then    begin      if (not DiskMustBeInDrive) or DiskInDrive(C) then      Include(Result, C);    end;  end;end; 
And from a unit that imlements a DriveCombobox:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type   TDriveType = (dtUnknown, dtNoRootDir, dtRemovable, dtFixed, dtRemote, dtCdrom, dtRamDisk);  TDriveTypes = set of TDriveType; function GetDriveType(ADrive: Char): TDriveType;var  WinDriveType: UINT;begin  WinDriveType := Windows.GetDriveType(PChar(LowerCase(ADrive+':\')));  case WinDriveType of    DRIVE_UNKNOWN: Result := dtUnknown;    DRIVE_NO_ROOT_DIR: Result := dtNoRootDir;    DRIVE_REMOVABLE: Result := dtRemovable;    DRIVE_FIXED: Result := dtFixed;    DRIVE_REMOTE: Result := dtRemote;    DRIVE_CDROM: Result := dtCdrom;    DRIVE_RAMDISK: Result := dtRamDisk;    else Result := dtUnknown;  end; //caseend;//refreshs the drive list//FMountedDrivesOnly: if True then disk must be in drive//DriveTypes: a set of drivetypes you want in the list, so you can e.g. filter for only removable drives procedure TFSICustomDriveComboBox.RefreshDriveList;var  C: Char;  ADriveType: TDriveType;begin  if (csDesigning in ComponentState) then    Exit;  Items.Clear;  for C in GetAvailableDrives(FMountedDrivesOnly) do  begin    ADriveType := GetDriveType(C);    if ADriveType in DriveTypes then      Items.Add(C + ':\');  end;  if FSelectFirstDriveOnRefreshDriveList and (not DroppedDown) and (Items.Count > -1) then    ItemIndex := 0;end; 
Bart

Sieben:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---... and (Items.Count > -1)
?

Bart:

--- Quote from: Sieben on November 20, 2020, 06:48:24 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---... and (Items.Count > -1)
?

--- End quote ---

Oops, must be > 0 of course.
Must have been confused with ItemIndex. Count of course can never be < 0.

Thanks.
Fixed in trunk.

Files reside here: https://svn.code.sf.net/p/flyingsheep/code/trunk/MijnLib
Units fsiwinutils and fsiwincontrols.

Bart

Sieben:
Thanks for sharing. And Flying Sheep is one of my absolute favourites as well...  :)

Remy Lebeau:

--- Quote from: Bart on November 20, 2020, 06:22:35 pm ---
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
--- End quote ---

Just to point out that SetErrorMode() is global to the whole process and changing its mode introduces a race condition in multi-threaded code.  You really should be using SetThreadErrorMode() instead.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version