Identify Drives/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | 1 | Zurück zu den [[Additional information/de|Zusätzlichen Informationen]].\ | |
| 3 | - | ||
| 2 | + | ||
| 4 | 3 | Dieser Artikel gehört zur Windowsprogrammierung.\ | |
| 5 | 4 | Aufgabe: Ermittlung aller Laufwerke\ | |
| 6 | 5 | ||
| 7 | 6 | ``` pascal | |
| 8 | 7 | uses | |
| 9 | 8 | Windows, SysUtils, ...; | |
| 10 | 9 | ||
| 11 | 10 | ... | |
| 12 | 11 | ||
| 13 | 12 | // Liste der zulässigen Laufwerktypen und ihre Werte | |
| 14 | 13 | { DRIVE_UNKNOWN = 0; | |
| 15 | 14 | DRIVE_NO_ROOT_DIR = 1; | |
| 16 | 15 | DRIVE_REMOVABLE = 2; | |
| 17 | 16 | DRIVE_FIXED = 3; | |
| 18 | 17 | DRIVE_REMOTE = 4; | |
| 19 | 18 | DRIVE_CDROM = 5; | |
| 20 | 19 | DRIVE_RAMDISK = 6;} | |
| 21 | 20 | ||
| 22 | 21 | var | |
| 23 | 22 | i: longword; | |
| 24 | 23 | arrLW: array[0..255] of char; | |
| 25 | 24 | pLW: PChar; | |
| 26 | 25 | ||
| 27 | 26 | begin | |
| 28 | 27 | ||
| 29 | 28 | ... | |
| 30 | 29 | ||
| 31 | 30 | // Ermittelt die Anzahl aller Laufwerke | |
| 32 | 31 | // und füllt das übergebene Char-Array arrLW mit den Laufwerken | |
| 33 | 32 | i := GetLogicalDriveStrings(SizeOf(arrLW), arrLW); | |
| 34 | 33 | ||
| 35 | 34 | // Prüft, ob ein Laufwerk gefunden wurde | |
| 36 | 35 | // Abbruch, wenn kein Laufwerk gefunden wurde | |
| 37 | 36 | if i <= 0 then | |
| 38 | 37 | Exit; | |
| 39 | 38 | ||
| 40 | 39 | // Prüft, ob die Anzahl der Laufwerke grösser als das Array ist | |
| 41 | 40 | // Im Fehlerfall wird eine Exception geworfen | |
| 42 | 41 | if i > SizeOf(arrLW) then | |
| 43 | 42 | raise Exception.Create(SysErrorMessage(ERROR_OUTOFMEMORY)); | |
| 44 | 43 | ||
| 45 | 44 | // Weist das Array mit den Laufwerken einem PChar zu | |
| 46 | 45 | pLW := arrLW; | |
| 47 | 46 | ||
| 48 | 47 | // Prüft, ob der Zeiger des PChars noch auf einen gültigen Bereich zeigt | |
| 49 | 48 | while pLW^ <> #0 do | |
| 50 | 49 | begin | |
| 51 | 50 | // Prüft, ob es sich bei dem Laufwerk zum einen gültigen Laufwerkstyp handelt | |
| 52 | 51 | if (GetDriveType(pLW) > DRIVE_UNKNOWN) then | |
| 53 | 52 | // weist den Laufwerksbuchstaben z. B. einer Combobox zu | |
| 54 | 53 | frmFormular1.cmbLaufwerke.Items.Add(pLW); | |
| 55 | 54 | // erhöht den Zeiger von pLW um 4 | |
| 56 | 55 | Inc(pLW, 4); | |
| 57 | 56 | ||
| 58 | 57 | end; | |
| 59 | 58 | ||
| 60 | 59 | ... | |
| 61 | 60 | ``` | |
| 62 | 61 | ||
| 63 | - | ||
| 64 | - | ||
| 65 | 62 | --Olaf 06:58, 28 April 2013 (UTC) | |
| 66 | 63 | ||
| 67 | 64 | --- | |
| 68 | 65 | *From the Free Pascal wiki, page "Identify Drives/de", as it stood on 2020-02-17 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).* | |
| 69 | 66 | Category: Tutorials | |
| 70 | 67 | Category: Windows |
