CD open close: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: CD open close
| Old | New | Line | |
|---|---|---|---|
| 1 | + | *(Windows only)* | |
| 2 | + | ||
| 3 | + | These procedures open and close a CD / DVD drive: | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | uses MMSystem, ...; | |
| 7 | + | ||
| 8 | + | ... | |
| 9 | + | ||
| 10 | + | procedure TForm1.Button1Click(Sender: TObject); | |
| 11 | + | begin | |
| 12 | + | // opens the CD-ROM drive | |
| 13 | + | mciSendstring('SET CDAUDIO DOOR OPEN', nil , 0, Form1.Handle); | |
| 14 | + | mciSendString ('close cdlw', nil, 0, 0) | |
| 15 | + | end; | |
| 16 | + | ||
| 17 | + | procedure TForm1.Button2Click (Sender: TObject); | |
| 18 | + | begin | |
| 19 | + | // closes the CD-ROM drive | |
| 20 | + | mciSendstring('SET CDAUDIO DOOR CLOSED', nil , 0, Form1.Handle); | |
| 21 | + | mciSendString ('close cdlw', nil, 0, 0) | |
| 22 | + | end; | |
| 23 | + | ||
| 24 | + | ... | |
| 25 | + | ``` | |
| 26 | + | ||
| 27 | + | If you want to wait until the last operation is finished then this procedure will open/close a CD-ROM/DVD depending on the value of the **blnOpen** boolean variable: | |
| 28 | + | ||
| 29 | + | ``` pascal | |
| 30 | + | uses | |
| 31 | + | MMSystem, ...; | |
| 32 | + | ||
| 33 | + | ... | |
| 34 | + | ||
| 35 | + | procedure cdOpenClose(chrDriveChar: char; blnOpen: boolean); | |
| 36 | + | begin | |
| 37 | + | if mciSendString(PChar('open ' + chrDriveChar + ': type cdaudio alias cdlw'), nil, 0, 0) = 0 then | |
| 38 | + | begin | |
| 39 | + | // open CD-ROM drive | |
| 40 | + | if blnOpen = True then | |
| 41 | + | mciSendString('set cdlw door open wait', nil, 0, 0) | |
| 42 | + | // close CD-ROM drive | |
| 43 | + | else | |
| 44 | + | mciSendString('set cdlw door closed wait', nil, 0, 0); | |
| 45 | + | ||
| 46 | + | mciSendString('close cdlw', nil, 0, 0); | |
| 47 | + | end; | |
| 48 | + | end; | |
| 49 | + | ||
| 50 | + | ... | |
| 51 | + | ||
| 52 | + | ``` | |
| 53 | + | ||
| 54 | + | --- | |
| 55 | + | *From the Free Pascal wiki, page "CD open close", as it stood on 2020-02-10 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).* |
