Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Pascal
Expertise: Beginner
Nov 4, 1998

Error Checking Using DriveComboBox Component

Question:
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.

Answer:
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; 
var
  //Volume Information Variables
  nVNameSer   : PDWORD;
  pVolName    : PChar;
  FSSysFlags,
  maxCmpLen   : DWord;
  pFSBuf      : PChar;
begin
  //initialize vars
  GetMem(pVolName, MAX_PATH);
  GetMem(pFSBuf, MAX_PATH);
  GetMem(nVNameSer, MAX_PATH);

  //Now, get the volume information
  Result := GetVolumeInformation(PChar(drv), 
             pVolName, MAX_PATH, nVNameSer,
             maxCmpLen, FSSysFlags, pFSBuf, 
             MAX_PATH);
end;
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap