Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2000, 06:33 AM
N/A
Guest
 
Posts: n/a
Default How can i know if there is disk in drive?



I have a programs that needs to read data from floppy disk and CD's!

every time i try to read and there is no disk or diskette i get I/O error!!!

how can i indicate if there is disk in the drive?
Reply With Quote
  #2  
Old 01-26-2000, 10:20 AM
N/A
Guest
 
Posts: n/a
Default RE: How can i know if there is disk in drive?

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







procedure TForm1.Button1Click(Sender: TObject);



begin



* *if CheckDriveOK('f: ') = False then



* * * *ShowMessage('Drive Not Ready')



* *else



* * * *ShowMessage('Drive is Fine');



end;







function TForm1.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;







Written by Brendan Delumpa on 11/4/98







This code was found at: http://www.inquiry.com/techtips/delphi_pro/answer.asp?pro=delphi_pro&docID=2419
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:19 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.