这段delphi代码哪里不对,怎么实现不了循环,请各位高手帮我看看!!!!!!
unitUnit2;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,F...
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MPlayer;
type
TForm2 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
MediaPlayer1: TMediaPlayer;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
str:string[20];
//str1:integer;
str2:string;
n:real;
i:integer;
begin
i:=0;
str:='57986';
edit1.Text := str;
while i < length(str) do
begin
i:=i+1;
str2:= copy(form2.edit1.Text ,i,1);
MediaPlayer1.FileName := 'D:\声音\' + str2+ '.wav';
MediaPlayer1.Open ;
MediaPlayer1.Play ;
//next;
end;
end;
end.
(我自己有声音文件,0到9,路径设的也没错)上面的代码运行后只语音输出最后一个"6",前面的"5798"不输出,请各位高手看看我的代码,让delhpi自带的组件MediaPlayer可以顺序,逐个的输出那串字符串"57986".
为什么不要用sleep做延迟?? 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MPlayer;
type
TForm2 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
MediaPlayer1: TMediaPlayer;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
str:string[20];
//str1:integer;
str2:string;
n:real;
i:integer;
begin
i:=0;
str:='57986';
edit1.Text := str;
while i < length(str) do
begin
i:=i+1;
str2:= copy(form2.edit1.Text ,i,1);
MediaPlayer1.FileName := 'D:\声音\' + str2+ '.wav';
MediaPlayer1.Open ;
MediaPlayer1.Play ;
//next;
end;
end;
end.
(我自己有声音文件,0到9,路径设的也没错)上面的代码运行后只语音输出最后一个"6",前面的"5798"不输出,请各位高手看看我的代码,让delhpi自带的组件MediaPlayer可以顺序,逐个的输出那串字符串"57986".
为什么不要用sleep做延迟?? 展开
展开全部
在MediaPlayer1.Play ;后面加一个延时函数试试,我想因为程序执行很快所以跟本没等前面几个声音播放过已经播放最后一个了,不过不要用Sleep做延时,可以使用下面这个函数
procedure Delay(MSecs: Longint);
//延时函数,MSecs单位为毫秒(千分之1秒)
var
FirstTickCount, Now: Longint;
begin
FirstTickCount := GetTickCount();
repeat
Application.ProcessMessages;
Now := GetTickCount();
until (Now - FirstTickCount >= MSecs) or (Now < FirstTickCount);
end;
因为sleep延时时程序会像死了一样停止相应,不过可以这样使用
Application.ProcessMessages;
sleep(1000);
procedure Delay(MSecs: Longint);
//延时函数,MSecs单位为毫秒(千分之1秒)
var
FirstTickCount, Now: Longint;
begin
FirstTickCount := GetTickCount();
repeat
Application.ProcessMessages;
Now := GetTickCount();
until (Now - FirstTickCount >= MSecs) or (Now < FirstTickCount);
end;
因为sleep延时时程序会像死了一样停止相应,不过可以这样使用
Application.ProcessMessages;
sleep(1000);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询