play sound in XE3

I was used to coding in Delphi 7 now I decided to try XE3 and I have come to a issue when playing a wav sound file.

I use "PlaySound(PChar('sound1'), hInstance, snd_resource or snd_async);"" in D7
but in XE3 it reports "undeclared identifier".

So my question is how do you play sounds in XE3?

thanks for any help



  • I don't think anything has changed. Delphi's PlaySound routine just calls the Windows API PlaySound routine. I don't think anything has changed there.
    I haven't used XE3 but I am currently working on an app in XE2 that plays sound from resource files and my code contains the line
    PlaySound(PChar(strSound), 0, SND_RESOURCE);
    This is pretty much what you have, and it works fine for me. The only real difference is that I pass 0 instead of hInstance, which should make no difference as 0 should default to the current app.

    All I can think is that in your XE3 code you don't have MMSystem in your uses clause.
  • SalmoSoft, you are once again the saviour, I forgot to put MMSystem in clauses, oops, I feel like a right fool, how mindless of me.

    Also with the part at the end (snd_async) PlaySound(PChar('sound1'), hInstance, snd_resource or snd_async); It plays the sound when the Help screen pops up, without snd_async it only displays the help screen once the sound finished playing.

    kindest regards
  • Oh Good. Glad you got it sorted.

    The choice of using snd_async or not obviously depends on your application. It is debatable in my app which is best. Currently I am not using it, but that may change before release. It sounds like your app is definitely better playing async.
Sign In or Register to comment.