Главная страница | назад





Article #16989: Removing drives listed in a TDriveComboBox

 Question and Answer Database
FAQ1989D.txt Removing drives listed in a TDriveComboBox
Category :VCL
Platform :All
Product :All 32 bit
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;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99