| 1:2:
 3:
 4:
 5:
 6:
 7:
 8:
 9:
 10:
 11:
 12:
 13:
 14:
 15:
 16:
 17:
 18:
 19:
 20:
 21:
 22:
 23:
 24:
 25:
 26:
 27:
 28:
 29:
 30:
 31:
 32:
 33:
 34:
 35:
 36:
 37:
 38:
 39:
 40:
 41:
 42:
 43:
 44:
 45:
 46:
 47:
 48:
 49:
 50:
 51:
 52:
 53:
 54:
 55:
 56:
 
 | uses mmSystem, ...
 {$R midi.res}
 procedure Midi(const aResName: String);
 const
 Len: Cardinal = MAX_PATH;
 tmpFile: String = '~tmpFile01'; var
 Stream: TCustomMemoryStream;
 BufLen, BufPos, tmpPath: String;
 begin
 SetLength(tmpPath, Len);
 GetTempPath(Len, PChar(tmpPath));
 tmpPath := StrPas(PChar(tmpPath)) + tmpFile;
 
 mciSendString('stop mySound', nil, 0, 0);
 mciSendString('close mySound', nil, 0, 0);
 if FileExists(tmpPath) then     DeleteFile(tmpPath);
 
 if FindResource(hInstance, PChar(aResName), 'MIDIFILE') <> 0 then
 begin     try
 Stream := TResourceStream.Create(hInstance, aResName, 'MIDIFILE');       Stream.SaveToFile(tmpPath);     finally
 Stream.Free;
 end;
 end
 else
 begin
 MessageBeep(MB_ICONEXCLAMATION);
 MessageDlg('Die Ressource kann nicht gefunden werden.', mtError, [mbOk], 0);
 Exit;
 end;
 
 mciSendString(PChar('open sequencer!' + tmpPath + ' alias mySound'), nil, 0, 0);
 mciSendString('play mySound' , nil, 0, 0);
 
 SetLength(BufLen, Len);
 SetLength(BufPos, Len);
 mciSendString('status mySound length', PChar(BufLen), Len, 0);   repeat
 mciSendString('status mySound position', PChar(BufPos), Len, 0);     Application.ProcessMessages;
 if Application.Terminated then
 break;
 until StrToInt(BufPos) >= StrToInt(BufLen);   mciSendString('stop mySound', nil, 0, 0);
 mciSendString('close mySound', nil, 0, 0);
 
 if FileExists(tmpPath) then     DeleteFile(tmpPath);
 end;
 |