I am finding it difficult to check whether an error has occurred in selecting a drive when it is not available at the time. I have tried to use IOResult when the change event takes place, but it doesn't seem to work. The error that occurs is I/O result 21. IOResult works with other I/O errors that occur, such as "file not found," but using IOResult with a component like DriveComboBox doesn't work. I would appreciate if you could help me solve this problem.
One way that I've found that works is to use the Windows API call GetVolumeInformation to test if a drive is ready. GetVolumeInformation will retrieve information like serial numbers and disk capacities. If GetVolumeInformation can read a drive it returns true, otherwise it returns false. I've written a wrapper function that will help you out with your problem:
This checks the drive to see if it's ready. If
GetVolumeInformation returns false, the drive isn't ready.
Value of Drv formal parameter should be something
like: 'C:\' or 'F:\'
function CheckDriveOK(Drv : String) : Boolean;
//Volume Information Variables
nVNameSer : PDWORD;
pVolName : PChar;
maxCmpLen : DWord;
pFSBuf : PChar;
//Now, get the volume information
Result := GetVolumeInformation(PChar(drv),
pVolName, MAX_PATH, nVNameSer,
maxCmpLen, FSSysFlags, pFSBuf,