事件为什么不触发呀?急(在线等)
各位大虾,请帮我看看这段程序怎么不触发事件?谢谢!
unit ThreadSendInfo;
interface
uses
Classes, Forms, ExtCtrls, SysUtils, StdCtrls, OleCtrls, SHDocVw, PubVar, DataFun;
type
TSendInfo = class(TThread)
private
WebSendInfo: TWebBrowser; //
MemoDisplay: TMemo; //
IfExecSend: Boolean; //
SendSign: Integer; //
typSendData: SendData_Type; //
{ Private declarations }
protected
procedure WebDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); //事件
procedure SendMsg();
procedure DataSearch();
procedure DBSetSign();
procedure Execute; override;
public
constructor Create(AMemo:TMemo);
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure SendInfoThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ SendInfoThread }
constructor TSendInfo.Create(AMemo:TMemo);
begin
inherited Create(False);
Priority:= tpIdle; //
FreeOnTerminate:= False; //
SendSign:= 0;
IfExecSend:= False;
WebSendInfo:= TWebBrowser.Create(Application);
WebSendInfo.OnDocumentComplete:= WebDocumentComplete;
MemoDisplay:= AMemo;
end;
procedure TSendInfo.Execute;
begin
{ Place thread code here }
while (not Terminated) or (IfExecSend) do
begin
if High(typWaitSendData) < 0 then
Synchronize(DataSearch);
if not ifExecSend then
Synchronize(SendMsg);
end;
end;
procedure TSendInfo.DataSearch();
begin
if funDBDataSearch <> 0 then
begin
if funConnDB = 0 then
funDBDataSearch
else if funConnDB = 0 then
funDBDataSearch;
end;
end;
procedure TSendInfo.SendMsg();
var
StrWeb: WideString;
begin
if (not IfExecSend) and (High(typWaitSendData) >= 0) then
begin
typSendData:= typWaitSendData[High(typWaitSendData)];
StrWeb:= 'http://www.163.com';
IfExecSend:= True;
SendSign:= 9;
Synchronize(DBSetSign);
SetLength(typWaitSendData,High(typWaitSendData));
WebSendInfo.Navigate(StrWeb);
end;
end;
procedure TSendInfo.DBSetSign();
begin
while True do
begin
if funDBSetSign(typSendData.Sm_Num,SendSign) <> 0 then
begin
funConnDB;
end
else
begin
Break;
end;
end;
end;
procedure TSendInfo.WebDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
ovDoc :OleVariant; //取得网页的内容
ErrMsg :String; //错误信息
begin
////这个事件为什么不能触发呢/
ovDoc:=(Sender as TWebBrowser).Document;
if(Pos('该页无法显示',ovDoc.All.item.innerhtml) <> 0) then //网络不通或对方服务器关闭
begin
SendSign:= 0;
ErrMsg:= '网络不通或服务停止,请与系统管理员联系!'
end;
// Synchronize(DBSetSign);
end;
end.