unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
StdCtrls;
type
TForm5 =
class(TForm)
Button1: TButton;
IdHTTP1: TIdHTTP;
Memo1: TMemo;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form5: TForm5;
implementation
uses MSXML, XMLDoc,
ActiveX, XMLIntf;
{$R *.dfm}
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: IXMLNode;
TextNode: IXMLNode;
ResultNode: IXMLNode;
aPartes: TArray<
string>;
XML: TXMLDocument;
IdHTTP: TIdHTTP;
begin
IdHTTP := TIdHTTP.Create(Application);
try
XML := TXMLDocument.Create(Application);
try
XML.Active := True;
XML.Version := '
1.0';
XML.Encoding := '
UTF-16';
RequestNode :=
XML.AddChild('
spellrequest');
RequestNode.Attributes['
textalreadyclipped'] := '
0';
RequestNode.Attributes['
ignoredups'] := '
0';
RequestNode.Attributes['
ignoredigits'] := '
1';
RequestNode.Attributes['
ignoreallcaps'] := '
0';
TextNode :=
XML.CreateNode('
text');
TextNode.Text := Enty;
RequestNode.ChildNodes.Add(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;
procedure TForm5.Button1Click(Sender: TObject);
begin
QuerySpell(Edit1.Text, Memo1.Lines)
end;
end.