Disk in Drive: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 1 | + | The function checks whether there is a disk medium in the CD or DVD drive. | |
| 2 | 2 | ||
| 3 | - | ||
| 3 | + | ``` pascal | |
| 4 | + | uses | |
| 5 | + | SysUtils, ...; | |
| 4 | 6 | ||
| 5 | - | ||
| 7 | + | // enumeration for the return values | |
| 8 | + | grade | |
| 9 | + | byte = (enmNoDriveLetter, enmMoMedInserted, enmMedInserted, enmError); | |
| 6 | 10 | ||
| 7 | - | ||
| 8 | - | ||
| 11 | + | ... | |
| 9 | 12 | ||
| 10 | - | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - | ||
| 28 | - | ||
| 29 | - | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 13 | + | function funDiskInDrive (chrDrive : char) : byte; | |
| 14 | + | begin | |
| 45 | 15 | ||
| 46 | - | ||
| 16 | + | Result := enmNoDriveLetter; | |
| 17 | + | chrDrive := UpCase(chrDrive); | |
| 18 | + | ||
| 19 | + | // Checks whether the drive letter is valid. | |
| 20 | + | if not (chrDrive in ['A' .. 'Z']) then | |
| 21 | + | exit; | |
| 22 | + | ||
| 23 | + | // Checks if the drive contains media. | |
| 24 | + | try | |
| 25 | + | if DiskSize ( Ord ( chr drive ) - $ 40 ) <> - 1 then | |
| 26 | + | Result := enmMedInserted | |
| 27 | + | else | |
| 28 | + | Result := enmNoMedInserted; | |
| 29 | + | except | |
| 30 | + | Result := enmError; | |
| 31 | + | end; | |
| 32 | + | ||
| 33 | + | end; | |
| 34 | + | ||
| 35 | + | ... | |
| 47 | 36 | ``` | |
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 37 | + | ||
| 38 | + | Example of calling the function: | |
| 39 | + | ||
| 40 | + | ``` pascal | |
| 41 | + | ... | |
| 42 | + | ||
| 43 | + | case funDiskInDrive('F') of | |
| 44 | + | enmNoDriveLetter : ... ; | |
| 45 | + | enmNoMedInserted : ... ; | |
| 46 | + | enmMedInserted : ... ; | |
| 47 | + | Error : ... ; | |
| 48 | + | end; | |
| 49 | + | ||
| 50 | + | ... | |
| 58 | 51 | ``` | |
| 59 | 52 | ||
| 60 | 53 | --- | |
| 61 | - | ||
| 54 | + | *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](/wiki-contact).* |
