下面是整个程序代码,我的目的是实现分析edit里面的输入内容(不论是数字还是字母),然后将其读出来。
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtnrs, MPlayer, ExtCtrls;
type
TForm3 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Button1: TButton;
OleContainer1: TOleContainer;
procedure Edit1Enter(Sender: TObject);
procedure Edit2Enter(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function Analyz(Num:String;var NewArray:array of string):Boolean; //分析Edit.Text
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
function tForm3.Analyz(Num:String;var NewArray:array of string):Boolean; //分析Edit.Text
var
Str,NewStr: String;
i,j:Integer;
begin
Str :=Num;
j:=0;
result:=true;
NewStr:='%%';
if NewStr='%%' then
NewStr:='';
try
for i:=1 to Length(Str)+1 do
begin
if str[i] in ['0','1'..'9'] then
Newstr:=NewStr+Str[i]
else if Str[i] in ['a','b'..'z','A','B'..'Z'] then //当Str[i]是字母时
begin
if NewStr='' then //如果NewStr中还不存在记录,第一个是字母
begin
NewArray[j]:=Str[i];
j:=j+1;
end
else //如果第一个不是字母,而是数字
begin
Case Length(NewStr) of
1: //只有一个数字时
NewArray[j]:=NewStr;
2:
begin {有两个数字时}
if NewStr[1]='0' then //两个数字中,第一个为'0'时
begin
NewArray[j]:=NewStr[1];
j:=j+1;
if NewArray[j]<>'0' then
NewArray[j]:=NewStr[2];
end
else
begin
NewArray[j]:=NewStr[1]; //两个数字中,第一不个为'0'时
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='10';
j:=j+1;
if NewArray[j]<>'0' then
NewArray[j]:=NewStr[2];
end;
end;
3: {有三个数字时}
begin
if NewStr[1]='0' then //三个数字中,第一个为'0'时
begin
NewArray[j]:=NewStr[1];
j:=j+1;
if copy(NewStr,2,2)<>'00' then
NewArray[j]:=NewStr[2];
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='10';
j:=j+1;
if NewArray[j]<>'0' then
NewArray[j]:=NewStr[3];
end
else
begin
NewArray[j]:=NewStr[i]; //三个数字中,第一个不为'0'时
j:=j+1;
NewArray[j]:='100';
j:=j+1;
if copy(NewStr,2,2)<>'00' then
NewArray[j]:=NewStr[i];
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='10';
j:=j+1;
if NewArray[j]<>'0' then
NewArray[j]:=NewStr[i];
end;
end;
4: {有四个数字时}
begin
if NewStr[1]='0' then //四个数字中,第一个为'0'时
begin
NewArray[j]:=NewStr[1];
j:=j+1;
if copy(NewStr,2,3)<>'000' then
NewArray[j]:=NewStr[2];
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='100';
j:=j+1;
if copy(NewStr,3,2)<>'00' then
NewArray[j]:=NewStr[3];
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='10';
j:=j+1;
if NewArray[j]<>'0' then
NewArray[j]:=NewStr[i];
end
else
begin
NewArray[j]:=NewStr[1]; //四个数字中,第一个不为'0'时
j:=j+1;
NewArray[j]:='1000';
j:=j+1;
if copy(NewStr,2,3)<>'000' then
NewArray[j]:=NewStr[2];
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='100';
j:=j+1;
if copy(NewStr,3,2)<>'00' then
NewArray[j]:=NewStr[3];
j:=j+1;
if NewArray[j-1]<>'0' then
NewArray[j]:='10';
j:=j+1;
if NewArray[j]<>'0' then
NewArray[j]:=NewStr[4];
end;
end;
end
end;
end ;
Newstr:='';
end;
except
result:=false;
end;
end;
procedure TForm3.Edit1Enter(Sender: TObject);
begin
Button1.Enabled:=true;
end;
procedure TForm3.Edit2Enter(Sender: TObject);
begin
button1.Enabled:=true;
end;
procedure TForm3.Button1Click(Sender: TObject);
procedure readavi(Newarray:array of string);
var
MediaPlayer1:TMediaPlayer;
i:Integer;
begin
for i:=0 to 20 do
begin
IF newarray[i]<>'' then
begin
MediaPlayer1:=TMediaPlayer.Create(self);
MediaPlayer1.Parent:=form3;
MediaPlayer1.FileName:='D:\医院智能管理系统\wav\wav\'+NewArray[i]+'.wav';
MediaPlayer1.Open;
MediaPlayer1.DeviceType:=dtAVIVideo;
MediaPlayer1.Play;
sleep(500);
MediaPlayer1.Free;
end
end;
end;
var
MediaPlayer1:TMediaPlayer;
NewArray:array[0..20] of string ;
begin
// Analyz(edit1.Text,NewArray);
MediaPlayer1:=TMediaPlayer.Create(self);
MediaPlayer1.Parent:=form3;
MediaPlayer1.FileName:='D:\医院智能管理系统\wav\wav\qing.wav';
MediaPlayer1.Open;
MediaPlayer1.DeviceType:=dtAVIVideo;
MediaPlayer1.Play;
sleep(500);
MediaPlayer1.Free;
Analyz(edit1.Text,NewArray);
readavi(NewArray);
sleep(200);
MediaPlayer1:=TMediaPlayer.Create(self);
MediaPlayer1.Parent:=form3;
MediaPlayer1.FileName:='D:\医院智能管理系统\wav\wav\haogukedao.wav';
MediaPlayer1.Open;
MediaPlayer1.DeviceType:=dtAVIVideo;
MediaPlayer1.Play;
sleep(1500);
MediaPlayer1.Free;
sleep(200);
Analyz(edit2.Text,NewArray);
readavi(NewArray);
sleep(200);
MediaPlayer1:=TMediaPlayer.Create(self);
MediaPlayer1.Parent:=form3;
MediaPlayer1.FileName:='D:\医院智能管理系统\wav\wav\haochuangkou.wav';
MediaPlayer1.Open;
MediaPlayer1.DeviceType:=dtAVIVideo;
MediaPlayer1.Play;
sleep(1400);
MediaPlayer1.Free;
end;
end.