uses
Classes, SysUtils, FileUtil, IdHTTP, Forms, Controls, Graphics, Dialogs,
StdCtrls,
DOM, XMLWrite;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
IdHTTP1: TIdHTTP;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
function QuerySpell(Enty:
string; ResultList: TStrings): Boolean;
const
C_URL = '
http://www.google.com/tbproxy/spell?lang=dt';
var
oRequest: TStringStream;
oResponse: TStringStream;
sResponse:
string;
sRequest:
string;
sResult:
string;
RequestNode: TDOMNode;
TextNode: TDOMNode;
ResultNode: TDOMNode;
//aPartes: TArray<string>;
XML: TXMLDocument;
IdHTTP: TIdHTTP;
begin
IdHTTP := TIdHTTP.Create(Application);
try
XML := TXMLDocument.Create;
try
//XML.Active := True;
//XML.Version := '1.0';
//XML.Encoding := 'UTF-16';
RequestNode :=
XML.CreateElement('
spellrequest');
TDOMElement(RequestNode).SetAttribute('
textalreadyclipped', '
0');
TDOMElement(RequestNode).SetAttribute('
ignoredups', '
0');
TDOMElement(RequestNode).SetAttribute('
ignoredigits', '
1');
TDOMElement(RequestNode).SetAttribute('
ignoreallcaps', '
0');
TextNode :=
XML.CreateElement('
text');
//TextNode.Text := Enty; in lazarus ?
RequestNode.ChildNodes.Item[0].AppendChild(TextNode);
XML.SaveToXML(sRequest);
sRequest := StringReplace(sRequest, '
UTF-16', '
UTF-8', [rfReplaceAll]);
oRequest := TStringStream.Create('
');
try
oRequest.WriteString(sRequest);
oRequest.Seek(0, 0);
IdHTTP.Request.Accept := '
text/xml';
IdHTTP.Request.ContentType := '
text/xml';
IdHTTP.Request.ContentEncoding := '
utf-8';
oResponse := TStringStream.Create('
');
try
IdHTTP.Post(C_URL, oRequest, oResponse);
sResponse := UTF8ToString(RawByteString(oResponse.DataString));
XML.Active := False;
XML.LoadFromXML(sResponse);
ResultNode :=
XML.DocumentElement.ChildNodes.FindNode('
c');
while (Assigned(ResultNode))
do
begin
ResultList.Add(StringReplace(ResultNode.Text,#9,#13#10,[rfReplaceAll]));
ResultNode := ResultNode.NextSibling;
end;
Result := True;
finally
oRequest.Free;
end;
finally
oResponse.Free;
end;
finally
XML.Free;
end;
finally
IdHTTP.Free;
end;
end;
end.