⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 从英文单词提取、到网上下载翻译
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP, OleCtrls, SHDocVw,MSHTML, ExtCtrls, DB, ADODB,
  ComCtrls;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    Button1: TButton;
    Memo1: TMemo;
    Memo2: TMemo;
    Timer1: TTimer;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Label3: TLabel;
    ProgressBar1: TProgressBar;
 

   procedure Button1Click(Sender: TObject);
 
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
   myi,myii:integer;
   word,flag:string;
implementation

{$R *.dfm}
function GetStr(StrSource,StrBegin,StrEnd:string):string;
var
in_star,in_end:integer;
begin


in_star:=AnsiPos(strbegin,strsource)+length(strbegin);
in_end:=AnsiPos(strend,strsource);
result:=copy(strsource,in_star,in_end-in_star);
sleep(100)
end;

procedure TForm1.Button1Click(Sender: TObject);
var
strsource:string;
i:integer ;
FHTTPClient:TIdHTTP;
mybuff:string;
 sql,buff,buf:string;
begin
while adoquery2.FieldByName('翻译').AsString<>'' do
begin
   adoquery2.Next;
   myii:=myii+1;
 end;
  memo2.Text :=inttostr( myii);

if (myii<form1.adoquery2.RecordCount) then
     begin
        myii:=myii+1;
         word:= adoquery2.FieldByName('单词').AsString ;
         adoquery2.Next;
         memo1.Text:=memo1.Text+word+#13#10;
       ProgressBar1.StepIt;
end;
   {

//下载
      FHTTPClient   :=   TIdHTTP.Create(   Self   ); 
          with   FHTTPClient   do
                begin
                    Disconnect;
                    Request.Pragma   :=   'no-cache ';
                    Request.CacheControl   :=   'no-cache ';
                    Request.Connection   :=   'close';
                    ReadTimeout     :=   1000   *   20   *   1;//1分钟超时
  mybuff :=idhttp1.get('http://baidu.netat.net/trans.php?sen='+word+'&lang=encn');
                end;
 freeandnil(FHTTPClient);     // 下载
buff:=getstr(mybuff,'<div style="width:100%;height:200px;" id="result">','以上结果由') ;

buff:=copy(buff,0,pos('<',buff)-1);
buf:=getstr(mybuff,'<textarea name="sen" rows="6" id="source">','</textarea></td>') ;

 sleep(100);
 
 sql:='update lib set 翻译='+#39+buff+#39+' where 单词='+#39+buf+#39;
              form1.adoquery1.Close;
              form1.adoquery1.SQL.Clear;
             try
              form1.adoquery1.SQL.Add(sql);
              form1.adoquery1.ExecSQL
              except
           end;     }
end;   



procedure TForm1.FormCreate(Sender: TObject);
var
sql,st:string;
begin
myi:=1;
myii:=0;
//flag:='start';
flag:='stop';
    st:=ExtractFilePath(Application.ExeName);
  adoquery1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+st+'english.mdb;Persist Security Info=False';
    adoquery2.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+st+'english.mdb;Persist Security Info=False';
    form1.adoquery2.Close;
         form1.adoquery2.SQL.Clear;
        sql:='select * from lib order by 单词';
         form1.adoquery2.SQL.Add(sql);
         form1.adoquery2.Open ;
       label3.Caption:='一共有'+ inttostr(form1.adoquery2.RecordCount)+'条记录!';


end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
button1.Click;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -