Back


Lennie's Weekly Tip : Is my Disk-Drive Ready!

Sunday, 14 November 1999 Ref. 04


You may sometimes need to check if the user's disk-drive is ready and has a disk inserted, to accomplish this you can use the following function:

function DiskDriveReady (Drive : byte) : boolean;

 begin
   if (DiskFree(Drive) <> -1) then
     DiskDriveReady := True
   else
     DiskDriveReady := False;
 end; {DisketteDriveReady}

The parameter "Drive" specifies the drive to check;
 


The function will return TRUE if the disk-drive is ready (with a disk inserted) or FALSE, otherwise.

To use it simply place a label (TLabel) and button (TButton) on a form (TFrom), and write the following code in the button's OnClick event-handler.

if (DiskDriveReady(1)) then
  Label1.Caption := 'Disk-drive is ready...'
else
  Label1.Caption := 'Disk-drive isn't ready...';

When you run the application (press F9) and click on the button, you'll hear a working sound coming from the disk-drive. The label will respond with a message telling you if the drive is ready or not.

To test it yourself, insert a disk into drive A: (I assume that your disk-drive is drive A)  and run the program again, remove the disk and the result will change.

This tip is very helpful, if you're writing a installation-application and want to check if the user had inserted the second installation-disk.


Back