K
kofoun
Unregistered / Unconfirmed
GUEST, unregistred user!
我现在想通过按钮,单击后,让声音发声,但发声时,窗体界面是不能动的,所以我创建了一个线程实现可以使窗体动,但有问题如下:
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,mmsystem, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
//function playsoundx:boolean;
implementation
{$R *.dfm}
function playsoundx:boolean;
var
i:integer;
begin
for i:=0 to 2do
begin
sndplaysound('c:/C:/WINDOWS/MEDIA/ding.wav',0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Ehandle:Thandle;
begin
Ehandle:=createThread(nil,0,@playsoundx,nil,0,ThreadID);
if ThreadID=0 then
begin
playsoundx;
end;
end;
end.
底部错误如下:
[Warning] Unit1.pas(36): Return value of function 'playsoundx' might be undefined
[Error] Unit1.pas(42): Undeclared identifier: 'ThreadID'
[Warning] Unit1.pas(43): Comparing signed and unsigned types - widened both operands
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,mmsystem, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
//function playsoundx:boolean;
implementation
{$R *.dfm}
function playsoundx:boolean;
var
i:integer;
begin
for i:=0 to 2do
begin
sndplaysound('c:/C:/WINDOWS/MEDIA/ding.wav',0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Ehandle:Thandle;
begin
Ehandle:=createThread(nil,0,@playsoundx,nil,0,ThreadID);
if ThreadID=0 then
begin
playsoundx;
end;
end;
end.
底部错误如下:
[Warning] Unit1.pas(36): Return value of function 'playsoundx' might be undefined
[Error] Unit1.pas(42): Undeclared identifier: 'ThreadID'
[Warning] Unit1.pas(43): Comparing signed and unsigned types - widened both operands
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'