- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Removing drives listed in a TDriveComboBox

Question:

On many laptop computers, there is a possibility that no floppy drive is installed. Is it possible to remove drives that are listed in the TDriveComboBox component to avoid listing non existent drives?

Answer:

The following example demonstrates removing drives that are not
ready for use from the TDriveComboBox component. Note that on many
computers, there will be a significant delay in checking for a plug
and play floppy drive.

Example:

procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
  OldErrorMode : Word;
  OldDirectory : string;
begin
  OldErrorMode := SetErrorMode(SEM_NOOPENFILEERRORBOX);
  GetDir(0, OldDirectory);
  i := 0;
  while i <= DriveComboBox1.Items.Count - 1 do begin
   {$I-}
    ChDir(DriveComboBox1.Items[i][1] + ':\');
   {$I+}
     if IoResult <> 0 then
       DriveComboBox1.Items.Delete(i) else
    inc(i);
  end;
  ChDir(OldDirectory);
  SetErrorMode(OldErrorMode);
end;



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile