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