1,594
社区成员




function URLEncode(const S: string; const InQueryString: Boolean): string;
var
Idx: Integer; // loops thru characters in string
begin
Result := '';
for Idx := 1 to Length(S) do
begin
case S[Idx] of
'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.':
Result := Result + S[Idx];
' ':
if InQueryString then
Result := Result + '+'
else
Result := Result + '%20';
else
Result := Result + '%' + SysUtils.IntToHex(Ord(S[Idx]), 2);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
word: string;
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
word := Memo2.Text;
IdHttp1.Get('http://translate.google.cn/translate_a/t?client=t&text=' + UrlEncode(Word, False) +'&sl=en&tl=zh-CN', ms);
ms.Position := 0;
Memo1.Lines.LoadFromStream(ms);
ms.Free;
end;