Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

Disk in Drive

Deutsch ยท English

The function checks whether there is a disk medium in the CD or DVD drive.

pascal
 uses
   SysUtils, ...;

 // enumeration for the return values
 grade
   byte = (enmNoDriveLetter, enmMoMedInserted, enmMedInserted, enmError);

  ...

 function funDiskInDrive (chrDrive : char) : byte;
 begin

   Result := enmNoDriveLetter;
   chrDrive := UpCase(chrDrive);

   // Checks whether the drive letter is valid.
   if not (chrDrive in ['A' .. 'Z']) then
     exit;

   // Checks if the drive contains media.
   try
     if DiskSize ( Ord ( chr drive ) - $ 40 ) <> - 1 then
       Result := enmMedInserted
     else
       Result := enmNoMedInserted;
   except
     Result := enmError;
   end;

 end;

   ...

Example of calling the function:

pascal
  ...

   case funDiskInDrive('F') of
     enmNoDriveLetter : ... ;
     enmNoMedInserted : ... ;
     enmMedInserted : ... ;
     Error : ... ;
   end; 
 
   ...

From the Free Pascal wiki, page "Disk in Drive", as it stood on 2020-02-13 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .