本文整理自网络,侵删。
uses MsXML, SuperObject;
//字符串到 UTF8 编码的函数, 用于 Google 地址function ToUTF8Encode(str: string): string;var b: Byte;begin for b in BytesOf(UTF8Encode(str)) do Result := Format('%s%s%.2x', [Result, '%', b]);end;
//翻译函数function Translate(str, RequestLanguage, ResultLanguage: string): string;const BaseUrl = 'http://fanyi.youdao.com/translate?&doctype=json&version&i=';var Url: string; jo: ISuperObject; req: IXMLHTTPRequest;begin Url := BaseUrl + ToUTF8Encode(str) ; req := CoXMLHTTP.Create; req.open('Get', Url, False, EmptyParam, EmptyParam); req.send(EmptyParam); // jo := SO(req.responseText); Result := req.responseText;//jo.Format('%translateResult%');end;
相关阅读 >>
Delphi 采用 tidhttp 访问 https 的网站,采用 tidtcpclient 访问 https 的网站
Delphi firedac 下的 sqlite [1] - 前言
Delphi winapi: getparent、setparent、movewindow - 获取、指定父窗口和移动窗口
Delphi windows 编程[10] - wm_lbuttondown、wm_lbuttonup 和 wm_mousemove 消息
更多相关阅读请进入《Delphi》频道 >>