for循环的问题!!!在线等待 (100分)

  • 主题发起人 super_duck
  • 开始时间
S

super_duck

Unregistered / Unconfirmed
GUEST, unregistred user!
我的代码
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
j,s:string;
begin
s:=copy(edit1.Text,4,5);
for i:=1 to edit1.MaxLength-3 do
begin
j:=copy(s,i,1);
edit2.Text:=j;
if j='1' then
begin
PlaySound('d://sound//1.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='2' then
begin
PlaySound('d://sound//2.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='3' then
begin
PlaySound('d://sound//3.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='4' then
begin
PlaySound('d://sound//4.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='5' then
begin
PlaySound('d://sound//5.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='6' then
begin
PlaySound('d://sound//6.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='7' then
begin
PlaySound('d://sound//7.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='8' then
begin
PlaySound('d://sound//8.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='9' then
begin
PlaySound('d://sound//9.wav',SND_APPLICATION,SND_FILENAME);
end;
if j='0' then
begin
PlaySound('d://sound//0.wav',SND_APPLICATION,SND_FILENAME);
end;
end;
end;
 
是不是NT4驱动程序有问题?
 
是不是要装 Windows Medai Player
 
在线等待啊~~~~~
 
这是c的写法 d://sound//1.wav 斜杠/为转义符
delphi的写法应该是 d:/sound/1.wav
 
for i:=1 to edit1.MaxLength-3 do
begin
j:=copy(s,i,1);
edit2.Text:=j;
path:='d://sound//'+j+'.wav';
// if j='1' then
// begin
PlaySound(pchar(path),SND_APPLICATION,SND_FILENAME);
// end;
 
同意楼上的
 
试试:
PlaySound('d://sound//1.wav',SND_APPLICATION,SND_FILENAME or SND_SYNC );
 
还是不行啊,5555555
 
什么现象?
 
编译不报错,运行时不发声
单独用:PlaySound('d:/sound/1.wav',SND_APPLICATION,SND_FILENAME);
时要发声的。
 
for i:=1 to edit1.MaxLength-3 do
begin
j:=copy(s,i,1);
edit2.Text:=j;
path:='d://sound//'+j+'.wav';PlaySound(pchar(path),SND_APPLICATION,SND_FILENAME);
..............
这个同意
 
s:=copy(edit1.Text,4,5);
for i:=1 to edit1.MaxLength-3 do
begin
j:=copy(s,i,1);
edit2.Text:=j;
FileName:='d://Sound//'+J+'.Wav';
PlaySound(FileName,SND_APPLICATION,SND_FILENAME);
end;
 
听死水的
delphi中不需要转义符。其实你单独调用时写对了
按ctrl+r
replace // with /搞定.
 
没对,没对
 
在最后一个if语句后加个sleep(100)给程序一点反应时间,循环执行速度是很快的,第一个还没播就要播第二个当然没声音啦。[:D]
 
for i:=1 to edit1.MaxLength-3 do
如此的for???电脑怎么pay啊???太快了,而且,你for i :=1 to Length(Edit1.Text) do
不能for i:=1 to edit1.MaxLength-3 do!!!!!!!!!1
 
这么多的if,干吗不用case呢,真是头痛
另外同意上面说的
 
字符串路径的写法不对头。怎么用转义符呢?“/"
 
PlaySound 我没用过,不过以上程序可简化:
s:=copy(Trim(edit1.Text),4,5);
// for i:=1 to edit1.MaxLength-3 do 错误!
for i :=1 to length(s) do
begin
edit2.Text:=s;
PlaySound('d:/sound/'+s+'.wav',SND_APPLICATION,SND_FILENAME);
//或 PlaySound(pchar('d:/sound/'+s+'.wav'),SND_APPLICATION,SND_FILENAME); 视参数情况而定
//此处加入控制时间延迟的代码, sleep(), pressmessagess 等;
end;
 
顶部