Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CD routines

Posted on 2001-06-27
7
Medium Priority
?
246 Views
Last Modified: 2010-04-06
I need 3 routines: Eject, Retract and Count tracks(without using MediaPlayer).

I know there is an mcisendstring or something like that but it does not handle the situation of having more than one CD drive(for example if someone has CD and CDR)
0
Comment
Question by:duke_n
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6231516
uses MMSystem;


// to open
mciSendString('Set cdaudio door open wait', nil, 0, handle);

// yo close
mciSendString('Set cdaudio door closed wait', nil, 0, handle);


I have no idea how to count the tracks...
0
 
LVL 1

Author Comment

by:duke_n
ID: 6231595
And what If I wanna do that(eject/retract) to the second/third/../twentieth CD?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6231805
Here's roughly how to get the number of tracks:

var mciOpenParms: TMCI_Open_Parms;
    mciStatusParms: TMCI_Status_Parms;
    mciSetParms: TMCI_Set_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE, Cardinal(@mciOpenParms));
  mciStatusParms.dwItem := MCI_STATUS_NUMBER_OF_TRACKS;
  if mciSendCommand(mciOpenParms.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@mciStatusParms)) = 0 then
    ShowMessage(IntToStr(mciStatusParms.dwReturn));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Accepted Solution

by:
Epsylon earned 400 total points
ID: 6232115
Ok here is is:

uses MMSystem;

const
  DRIVE = 'G:';

procedure TForm1.GetNumberOfTracksClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
    mciStatusParms: TMCI_Status_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciStatusParms.dwItem := MCI_STATUS_NUMBER_OF_TRACKS;
  if mciSendCommand(mciOpenParms.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM, Cardinal(@mciStatusParms)) = 0 then
    ShowMessage(IntToStr(mciStatusParms.dwReturn));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;

procedure TForm1.OpenCDClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;

procedure TForm1.CloseCDClick(Sender: TObject);
var mciOpenParms: TMCI_Open_Parms;
begin
  mciOpenParms.lpstrDeviceType := 'cdaudio';
  mciOpenParms.lpstrElementName := DRIVE;
  mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_ELEMENT, Cardinal(@mciOpenParms));
  mciSendCommand(mciOpenParms.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
  mciSendCommand(mciOpenParms.wDeviceID, MCI_CLOSE, 0, 0);
end;
0
 
LVL 1

Author Comment

by:duke_n
ID: 6232207
exceptional.
thank you very much.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6232217
Here is how to find CDROM drives:

procedure ListDrives(Strings: TStrings);
const BufSize = 256;
var
  Buffer: PChar;
  P: PChar;
begin
  GetMem(Buffer, BufSize);
  try
    Strings.BeginUpdate;
    try
      Strings.Clear;
      if GetLogicalDriveStrings(BufSize, Buffer) <> 0 then
      begin
        P := Buffer;
        while P^ <> #0 do
        begin
          if GetDriveType(PChar(P)) = DRIVE_CDROM then
            Strings.Add(P);
          Inc(P, StrLen(P) + 1);
        end;
      end;
    finally
      Strings.EndUpdate;
    end;
  finally
    FreeMem(Buffer, BufSize);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ListDrives(ListBox1.Items);
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6232221
Thanks  :o)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question