Sign in Join
Wiki copytemporary

Revision 1 of 2, by WikiArchive on 11-4-2026. The page as it is now.

Disk in Drive

https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Windows_logo_-_2012.svg/50px-Windows_logo_-_2012.svg.png

This article applies to Windows only.

See also: Multiplatform Programming Guide

│ Deutsch (de) │ English (en) │


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 the Internet Archive kept it on 2025-04-21. 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.