线程加载返回的XMLtoTClientDataSet
TReadOrderThread = class(TThread)
private
FCDS: TClientDataSet;
Fstr: string;
protected
procedure Execute; override;procedure readOrder;
function XMLToDataSet(strXML:WideString;nodeName:string):TClientDataSet;
public
constructor Create(str:string); overload;
end;
function PostWebPage(url,para:String;TimeOut:Integer):WideString;
var
tmpWeb:TIdHTTP;
IdSSL : TIdSSLIOHandlerSocketOpenSSL;
retrun:String;
Proxy:String;
i:Integer;
paralist:TStrings;
Response2: TStringStream;
begin
retrun:='';
try
//Response2:= TStringStream.Create('');
paralist:=TStringList.Create;
paralist.Text:=StringReplace(para,'&',#13#10,[rfReplaceAll]);
IdSSL:= TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSL.SSLOptions.Method:=sslvSSLv3;
tmpWeb:=TIdHTTP.Create(nil);
tmpWeb.IOHandler:=IdSSL;
tmpWeb.ReadTimeout:=TimeOut;
tmpWeb.Request.ContentType:='application/x-www-form-urlencoded';
try
retrun:=tmpWeb.Post(url,paralist);
except
on e:exception do
showmessage(e.Message);
end;
sleep(500);
// retrun:=Utf8ToAnsi(paralist.Text);
finally
tmpWeb.Disconnect;
FreeAndNil(tmpWeb);
//Response2.Free;
FreeAndNil(paralist);
end;
Result:=retrun;
end;
constructor TreadOrderThread.Create(str:string);
begin
FreeOnTerminate := True;
Fstr := str;
FCDS:=TClientDataSet.Create(nil);
inherited Create(False);
end;
function TreadOrderThread.XMLToDataSet(strXML:WideString;nodeName:string):TClientDataSet;
var
myDataSet:TClientDataSet;
s:string;
xdoc : IXMLDOMDocument;
xdn :IXMLDOMNode;
xdns :IXMLDOMNodeList;
i,j:integer;
d,ii:integer;
sumtotal,sumje,dj,je:double;
sl:integer;
begin
myDataSet := TClientDataSet.Create(nil);
xdoc:=CreateDOMDocument();
xdoc.loadXML(strXML);
sumtotal:=0;
sumje:=0;
s:='';
xdn:=xdoc.documentElement;
xdns:=xdoc.selectNodes('//'+nodeName);
try
begin
try
for i:=0 to xdns.item[0].childNodes.length-1 do
begin
myDataSet.FieldDefs.Add(xdns.item[0].childNodes[i].nodeName,ftstring,1000);
end;
except
Application.MessageBox('没有查询到数据。','提示',32);
exit;
end;
try
myDataSet.CreateDataSet; //建立
myDataSet.Active;
except;
end;
d:=0;
for i:=0 to xdns.length-1 do
begin
myDataSet.Append;
myDataSet.FieldValues[xdns.item[i].childNodes[j].nodeName]:=xdns.item[i].childNodes[j].text;
end;
myDataSet.Post;
end;
end;
except
on Ex:Exception do
begin
myDataSet:=nil;
FCDS.Active:=false;
end;
end;
result:=myDataSet;
end;
procedure TreadOrderThread.Execute;
var
OwnerData: OleVariant;
begin
try
FCDS.Active:=false;
//while not self.Terminated do
//begin
self.Synchronize(readOrder);
sleep(50);
// if (_total>(total/page)) or (total=0) then
// self.Terminate();
// end;
finally
// CoUninitialize;
end;
end;