以下的程式碼可偵測磁碟機是否存放磁片:

type
   TDriveState=( DS_NO_DISK, DS_UNFORMATTED_DISK, DS_EMPTY_DISK,
                DS_DISK_WITH_FILES );

Function DriveState( driveletter: Char ): TDriveState;
Var
   mask: String[6];
   sRec: TSearchRec;
   oldMode: Cardinal;
   retcode: Integer;
Begin
   oldMode:= SetErrorMode( SEM_FAILCRITICALERRORS );
   mask:= '?:\*.*';
   mask[1] := driveletter;
   {$I-}  { don't raise exceptions if we fail }
   retcode := FindFirst( mask, faAnyfile, SRec );
   If retcode = 0 Then FindClose( SRec );
   {$I+}
   ShowMessage(Format('FindFirst returned %d', [retcode]));
   case Abs(retcode) of
      0: Result := DS_DISK_WITH_FILES;  { found at least one file }
     18, 2: Result := DS_EMPTY_DISK;  { found no files but otherwise ok }
     21, 3: Result := DS_NO_DISK; { DOS ERROR_NOT_READY on WinNT,}
                                   {  ERROR_PATH_NOT_FOUND on Win 3.1 }
   else
     Result := DS_UNFORMATTED_DISK;
   end;
   SetErrorMode( oldMode );
End; { DriveState }


Peter Below (TeamB)  100113.1101@compuserve.com)

    Source: geocities.com/huanlin_tsai/faq

               ( geocities.com/huanlin_tsai)