Sign in Join
Wiki copytemporary

CD open close

Deutsch · English

(Windows only)

These procedures open and close a CD / DVD drive:

pascal
uses MMSystem, ...;

...

procedure TForm1.Button1Click(Sender: TObject);
begin
// opens the CD-ROM drive
mciSendstring('SET CDAUDIO DOOR OPEN', nil , 0, Form1.Handle);
mciSendString ('close cdlw', nil, 0, 0)
end;

procedure TForm1.Button2Click (Sender: TObject);
begin
// closes the CD-ROM drive
mciSendstring('SET CDAUDIO DOOR CLOSED', nil , 0, Form1.Handle);
mciSendString ('close cdlw', nil, 0, 0)
end;

...

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:

pascal
uses
  MMSystem, ...;
  
  ...
  
procedure cdOpenClose(chrDriveChar: char; blnOpen: boolean);
begin
  if mciSendString(PChar('open ' + chrDriveChar + ': type cdaudio alias cdlw'), nil, 0, 0) = 0 then
    begin
      // open CD-ROM drive
      if blnOpen = True then
        mciSendString('set cdlw door open wait', nil, 0, 0)
      // close CD-ROM drive
      else
        mciSendString('set cdlw door closed wait', nil, 0, 0);

      mciSendString('close cdlw', nil, 0, 0);
    end;
end;
  
  ...

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.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.