TLama 发布的答案是这段代码运行良好:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Bass;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
StreamHandle: HSTREAM;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
if BASS_Init(-1, 44100, 0, Handle, nil) then
begin
StreamHandle := BASS_StreamCreateFile(False, PChar('c:\Windows\Media\tada.wav'), 0,
0, 0 {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
BASS_StreamFree(StreamHandle);
BASS_Free;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
BASS_ChannelPlay(StreamHandle, True);
end;
end.