?? unit1.pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function getAnswer(aText: string): string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
sent, str1, str2: string;
sl1: TStringList;
i: integer;
begin
//IdHTTP1.Connect();
sl1:= TStringList.Create;
sent:= memo1.Lines[0];
for i:= 1 to memo1.Lines.Count- 1 do begin
sent:= sent+ ' '+ memo1.Lines[i];
end;
for i:= 1 to Length(sent) do begin
if sent[i]=' ' then begin
sent[i]:= '+';
end;
end;
str1:= 'http://translate.google.cn/translate_t?sl=en&hl=zh-CN&ie=GB2312&text='+ sent;
str2:= IdHTTP1.Post(str1, sl1);
memo2.Text:= getAnswer(str2);
sl1.free;
end;
function TForm1.getAnswer(aText: string): string;
var
i, a: integer;
begin
a:= pos('id=result_box', aText);
if a> 0 then begin
i:= a;
while (i< length(aText)) and (aText[i]<> '>') do begin
i:= i+ 1;
end;
i:= i+ 1;
result:= '';
while (i< length(aText)) and (aText[i]<> '<') do begin
result:= result+ aText[i];
i:= i+ 1;
end;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -