Board index » delphi » Mediaplayer error handling

Mediaplayer error handling

Hello people,
I want to let my program to figger out, if I have a cd-rom
but I cant find anything to do so, I have try something with
TRY an FINALLY but it dont work. this is wat i want:
---------------------------------
open mediaplayer1 cdrom {music cd}
if AnyError then
begin
 outtext('you dont have a cd-rom'
end else
begin
 mediaplayer1 play;
end;
---------------------------------
sorry for my kids-writing style.
my thanks is so big as your solution !

 

Re:Mediaplayer error handling


michel heeft geschreven in bericht <6b255d$l9...@news2.xs4all.nl>...

Quote
>Hello people,
>I want to let my program to figger out, if I have a cd-rom
>but I cant find anything to do so, I have try something with
>TRY an FINALLY but it dont work. this is wat i want:
>---------------------------------
>open mediaplayer1 cdrom {music cd}
>if AnyError then
>begin
> outtext('you dont have a cd-rom'
>end else
>begin
> mediaplayer1 play;
>end;
>---------------------------------
>sorry for my kids-writing style.
>my thanks is so big as your solution !

You could TRY this:

----------------------------- code starts
here ----------------------------------
try
  mediaplayer1.play;
except
  on EMCIDeviceerror do
  begin
    messagedlg('You don''t have CD-ROM', mtError,
      [mbOk], 0);
  end;
end;
----------------------------- code ends
here ----------------------------------

wish you good luck and lots of programfun!

Maurits van der Schee

Re:Mediaplayer error handling


Quote
>>michel heeft geschreven in bericht <6b255d$l9...@news2.xs4all.nl>...
>>Hello people,
>>I want to let my program to figger out, if I have a cd-rom
>>but I cant find anything to do so, I have try something with
>>TRY an FINALLY but it dont work. this is wat i want:

[And so on and so on]
Quote
>>my thanks is so big as your solution !

Then Maurits van der Schee wrote  <6b4ooa$t8...@trst.cca.vu.nl>...

Quote

>You could TRY this:

>try
>  mediaplayer1.play;
>except
>  on EMCIDeviceerror do
>  begin
>    messagedlg('You don''t have CD-ROM', mtError,
>      [mbOk], 0);
>  end;
>end;
>----------------------------- code ends
>here ----------------------------------

>wish you good luck and lots of programfun!

>Maurits van der Schee

A problem with this code is that even though you've got the "try except"
construction, you'll encounter a system error (one of these irritating white
screens saying 'can't read from drive. Cancel / Abort / Retry' ) when trying
to read from an empty CD-rom drive (or floppy drive).
What you can try to avoid these system errors is:

var
  TempErrorMode: Word;
begin
  TempErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  {This will disable the systemerrors, while storing the old errormode in
TempErrorMode}
try
  try {Now execute the code you don't want to be interupted by system
errors...}
     mediaplayer1.play;
  except
     on EMCIDeviceerror do
     begin
        messagedlg('You don''t have CD-ROM', mtError,[mbOk], 0);
     end;
  end;
finally  {Return the ErrorMode to it's original value}
  SetErrorMode(TempErrorMode);
end;

Other Threads