本文整理自网络,侵删。
{
delphi网络字典beta1
此程序原理及其简单,获取页面代码,正则
表达式匹配+微软TTS,大侠飘过。本人水平有限,
只用了不到1个小时完成,时间仓促,如有不妥,
望高手指出。
欢迎转载,发布,不过请保留此信息:
毒手药王:
http://hi.baidu.com/blackcode
}
unit main;
interface
uses
Windows,Graphics, Forms, SysUtils, WinSkinData, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, ComCtrls, StdCtrls, Controls,
RegExpr,SpeechLib_TLB,ActiveX,ShellAPI,
Classes;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
IdHTTP1: TIdHTTP;
Memo2: TMemo;
Memo3: TMemo;
Button2: TButton;
Button3: TButton;
Button4: TButton;
SkinData1: TSkinData;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
spvoice1:TSpVoice;
implementation
{$R *.dfm}
procedure readTxt(str:string); //id标识语言,由config配置
var
FileName:string;
istokens:ISpeechObjectTokens;
istoken:ISpeechObjectToken;
f:TextFile;
begin
{init spvoice}
CoInitialize(nil);
spvoice1:=TSpVoice.Create(nil);
istokens:=spvoice1.GetVoices('','');
spvoice1.Voice:=istokens.Item(0);
spvoice1.Speak(str,SVSFDefault);
spvoice1.Free;
end;
function GetName(TextToCheck:String;expre:string):string;//利用正则表达式过滤出链接
Var
myExpr: TRegExpr;
str:string ;
temp_result:string;
// list_str:TStringList;
begin
//list_str:=TStringList.Create;
myExpr := TRegExpr.Create;
//Form1.ComboBox1.Clear;
Try
myExpr.Expression :=expre;
if myExpr.Exec(TextToCheck) then
repeat
begin
temp_result:=temp_result+myExpr.Match[1]+#13#10;
end;
until not MyExpr.ExecNext;
finally
myExpr.Free;
end;
//list_str.SaveToFile('./channel.ini');
Result:=temp_result;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
if Edit1.Text='' then
begin
MessageBox(0,'丫头,是不是还没输入年?','提示',48);
Exit;
end;
Memo1.Clear;
statusbar1.SimpleText:='开始搜索网络资源,请稍候!长时间无响应,请检查您的网络!';
s:='http://www.dreye.com.cn:8080/dict/dict_gb.jsp?w='+edit1.Text;
s:=Trim(s);
Memo2.Text:=IdHTTP1.Get(s);
Memo1.Lines.Add('单词:'+GetName(Memo2.Text,'<div class=ptitle>(.*?)<'));///div>
memo1.Lines.add('拼音:'+getName(Memo2.Text,'<font class=chinese>(.*?)</font>'));
memo1.Lines.add('英文:'+getName(Memo2.Text,'<div class=pexplain>(.*?)</div>'));
StatusBar1.SimpleText:='成功找到资源!';
readTxt('ok find it!');
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
Button1.Click;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
threadId:DWORD;
begin
//CreateThread(nil,0,@readTxt,nil,0,ThreadId);
readTxt(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ShellExecute(handle,nil,pchar('http://hi.baidu.com/blackcode'),nil,nil,sw_shownormal);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//readTxt('Hello,Thanks for Use this Program,code by ADE');
end;
end.
相关阅读 >>
Delphi strtoint 将“字符型”转换成“整数型”
Delphi 网上获取北京时间idhttpserver and idhttp 使用 encoding utf8
Delphi 2009 新增单元 character[1]: toupper、tolower - 字符与字符串的大小写转换
Delphi shellexecute调用系统命令关闭计算机
更多相关阅读请进入《Delphi》频道 >>