unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, IdHTTP, Forms, Controls, Graphics, Dialogs,
StdCtrls,
DOM, XMLWrite, XMLRead;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
IdHTTP1: TIdHTTP;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
XMLString: TStrings;
SendStream, ResponseStream: TStringStream;
TextToCheck, Str1:
String;
XMLDoc : TXMLDocument;
i: Integer;
begin
TextToCheck := '
Wass ist mit dem getartetn Teest';
// der Satz (oder Wort) welcher geprüft / korrigiert werden soll
XMLString := TStringList.Create;
try
XMLString.Add('
<?xml version="1.0" encoding="UTF-8"?>');
XMLString.Add('
<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">');
XMLString.Add('
<text>' + TextToCheck + '
</text>');
XMLString.Add('
</spellrequest>');
IdHTTP1.Request.Accept := '
*/*';
IdHTTP1.Request.ContentType := '
text/xml';
IdHTTP1.Request.Connection := '
Keep-Alive';
IdHTTP1.HandleRedirects := True;
SendStream := TStringStream.Create(XMLString.Text);
ResponseStream := TStringStream.Create('
');
try
IdHTTP1.Post('
http://www.google.com/tbproxy/spell?lang=de', SendStream, ResponseStream);
Memo1.Text:= ResponseStream.DataString;
except
on E:
Exception do
ShowMessage('
Fehler: ' + E.
Message);
end;
//ResponseStream in XML-Format wandeln
ResponseStream.Position:= 0;
XMLDoc:=
Nil;
ReadXMLFile(XMLDoc,ResponseStream);
//Ausgabe der Wort-Vorschläge
for i:= 0
to (XMLDoc.DocumentElement.ChildNodes.Count - 1)
do
begin
Memo2.Lines.Add(utf8encode(XMLDoc.DocumentElement.ChildNodes.Item[i].FirstChild.TextContent));
//utf8encode wichtig ! sonst statt Umalauten nur '?'
end;
finally
FreeAndNil(ResponseStream);
FreeAndNil(XMLString);
FreeAndNil(SendStream);
FreeAndNil(XMLDoc);
end;
end;
end.