Sign in Join
Wiki copytemporary

Revision 2 of 2, by Trev on 2-10-2020. The page as it is now.

CD open close

https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Windows_logo_-_2012.svg/50px-Windows_logo_-_2012.svg.png

This article applies to Windows only.

See also: Multiplatform Programming Guide

│ Deutsch (de) │ English (en) │

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 the Internet Archive kept it on 2025-02-15, last changed on 2020-02-11. 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.