各位大虾,请帮我看看这段程序怎么不触发事件?谢谢!
unit ThreadSendInfo;interfaceuses
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.
unit ThreadSendInfo;interfaceuses
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.
解决方案 »
- sendmessage模拟鼠标移动
- ========奇怪的SQL语句======
- 如何从动态产生的组件中取数据。
- 关于自动生成编号的问题!
- 请问验证用户身分的对话框应该在何时创建?,怎么创建?
- 有什么方法截取用户按键,如按Power键截取后并不再继续、按windows键截取它并不再显示开始菜单
- 请问我编写的mts/com+应用程序,为什么在win2000里安装,必须要先装delphi7,才能在组件服务中com+装, 不然就报错!
- 在delphi下,如何把image控件中的图象写入SQL表的picture(image类型)字段。
- 加标志
- 如何做一个像foxmail一样可以导入outlook邮件,导入到文件或数据库都行.
- ADO的AsFloat返回的值有什么问题?
- 关于B/S系统的设计,请大家来讨论讨论。
如果想使用,按你的程序,就是调用这个procedure了。
你应该看看delphi中消息处理方面的资料,你的问题就基本可以解决了