线程定义单元:
unit InfoReload;
interface
uses
Classes,MSXML2_TLB,msxmldom,ADODB,Activex,SysUtils,Dialogs;
type
TInfoReload = class(TThread)
private
strHint:String;
tmpXml:IxmldomDocument;
iTop:integer;
tmpQ: TADOQuery;
strXml:String;
procedure CheckAndDown();
function DealOneString(objNode:IxmlDomNode):String;
function Filt_It(ss: string): string;
procedure EnTime();
procedure AddCountInfo();
{ Private declarations }
protected
procedure Execute;
override;
public
constructor Create(iGMjID:integer);
end;
implementation
uses Main,HDConst,forms,ComObj,Variants,Search,DateUtils,DbCmd,HDother;
{ Synchronize(UpdateCaption);
Sync }
constructor TInfoReload.Create(iGMjID:integer);
begin
inherited Create(False);
tmpxml := CreateOLEObject('Microsoft.XmlDom') as IXMLDOMDocument;
tmpxml.async :=false;
iTop:=iGMjID;
strXml:='';
FreeOnTerminate:= true;//false;
end;
procedure TInfoReload.CheckAndDown();
var NodeList:IXmlDomNodeList;
m:integer;
begin
try
tmpxml.load(ReloadUrl+'?iTop='+inttostr(iTop)+'&a1='+CopyRightString+'&uid='+uid);
{ while (tmpxml.readyState<>4)do
begin
application.ProcessMessages;
end;
}
if tmpxml.parseError.errorCode <> 0 then
begin
strHint:=(tmpXml.parseError.url+#13+tmpxml.parseError.reason+#13+tmpxml.parseError.srcText);
Exit;
end
else
begin
NodeList:=tmpXml.selectNodes('//One');
if (NodeList.length<1) then
exit
else
begin
strXml:='';
TmpQ := TAdoQuery.Create(nil);
TmpQ.CacheSize:=5;
TmpQ.Connection:=Conn;
for m:=NodeList.length-1do
wnto 0do
strXml:=strXml + DealOneString(NodeList[m]);
TmpQ.Free;
backXml:=strXml;
end;
//数据返回,处理之
end;
finally
//tmpxml:=nil;
end;
end;
function TInfoReload.DealOneString(objNode:IxmlDomNode):String;
var strTmp:string;
begin
//
Result:='';
if objNode=nil then
exit;
strTmp:=objNode.text;
//测试
//ssInfoString:=ssInfoString+'$' + strTmp +'#';
strTmp:=ParseOneString(strTmp,tmpQ,iTop);
if (strTmp='') then
strHint:='保存出错'
else
begin
Synchronize(AddCountInfo);
Result:=strTmp;
end;
end;
procedure TInfoReload.AddCountInfo();
begin
AddCount();
end;
procedure TInfoReload.EnTime();
begin
frmMain.InfoTimer.Enabled:=true;
frmMain.Caption:=InttoStr(iTop)+datetimetostr(now);
end;
procedure TInfoReload.Execute;
begin
CoInitialize(nil);
while not Terminateddo
begin
//Application.ProcessMessages;
// if (bReload=true) then
CheckAndDown();
sleep(100);
//Application.ProcessMessages;
// Synchronize(EnTime);
Suspend;
end;
showmessage('terminated');
iGetMaxjID:=iTop;
tmpxml:=nil;
CoUninitialize();
end;
function TInfoReload.Filt_It(ss: string): string;
var st: string;
begin
st := ss;
if ss <> '' then
begin
st := StringReplace(st, '&', '&amp;', [rfReplaceAll]);
st := StringReplace(st, '<', '&lt;', [rfReplaceAll]);
st := StringReplace(st, '>', '&gt;', [rfReplaceAll]);
st := StringReplace(st, '"', '&quot;', [rfReplaceAll]);
st := StringReplace(st, '''', '&apos;', [rfReplaceAll]);
end;
Result := st;
end;
end.
主窗体单元:
procedure Tck.Update;
begin
//showmessage('asfd');
//UpdateData();
bReload:=true;
if (thdReload<>nil) then
begin
try
thdReload.Terminate;
//.esume;
//.Free;
thdreload.WaitFor;
//.Resume;
if thdreload=nil then
begin
showmessage('real terminate and free');
end
else
showmessage('no terminate');
//showmessagRe('Resume');
except
showmessage('failed Resume');
end
end
else
thdReload:=TInfoReload.Create(iGetMaxjID);
end;