P
piaosiy
Unregistered / Unconfirmed
GUEST, unregistred user!
多线程下子线程要怎么样才能使用父线程资源?代码如下:
unit ufrmPing;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,ShellApi, StdCtrls, IdBaseComponent, IdComponent,
IdRawBase, IdRawClient, IdIcmpClient,IniFiles;
type
TfrmPing = class(TForm)
Memo1: TMemo;
Timer2: TTimer;
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ICMPping1(Ptrointer);stdcall;
var
frmPing: TfrmPing;
IPadr1,SFileName:string;
IP1IsReturn:boolean;
IdIcmpClient1: TIdIcmpClient;
implementation
{$R *.dfm}
procedure ICMPping1(Ptrointer);stdcall;
begin
if IP1IsReturn=False then
frmPing.Memo1.Lines.Add('Request timed out.');
//主要是上面这句。编译后运行会出现 "0x0045ecc3"指令引用的"0x000002f8"内存。该内存不能为"read"
的错误。
IdIcmpClient1.Host:=IPadr1;
//IdIcmpClient1为Form Create 的时候动态定义的,IPadr1 为欲发送ICMP包的IP地址
IdIcmpClient1.ReceiveTimeout:=2000;
IdIcmpClient1.Ping();
IP1IsReturn:=False;
//如有正确返回ICMP包(即能Ping通)此变量将置True.
end;
procedure TfrmPing.Timer2Timer(Sender: TObject);
//Form Create 时触发该定时器,间隔10秒触发一次。
var
IPping1:Thandle;
ThreadID1WORD;
begin
if Trim(IPadr1)<>'' then
begin
IPping1:= CreateThread(nil,0,@ICMPping1,nil,0,ThreadID1);
end;
end;
end.
整个程序是想实现一个类似于Ping命令的功能,这里仅给出了Ping 不通时出问题的关键部分,请问应如何修改才能解决该内存不能为"read"
的问题?
unit ufrmPing;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,ShellApi, StdCtrls, IdBaseComponent, IdComponent,
IdRawBase, IdRawClient, IdIcmpClient,IniFiles;
type
TfrmPing = class(TForm)
Memo1: TMemo;
Timer2: TTimer;
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ICMPping1(Ptrointer);stdcall;
var
frmPing: TfrmPing;
IPadr1,SFileName:string;
IP1IsReturn:boolean;
IdIcmpClient1: TIdIcmpClient;
implementation
{$R *.dfm}
procedure ICMPping1(Ptrointer);stdcall;
begin
if IP1IsReturn=False then
frmPing.Memo1.Lines.Add('Request timed out.');
//主要是上面这句。编译后运行会出现 "0x0045ecc3"指令引用的"0x000002f8"内存。该内存不能为"read"
的错误。
IdIcmpClient1.Host:=IPadr1;
//IdIcmpClient1为Form Create 的时候动态定义的,IPadr1 为欲发送ICMP包的IP地址
IdIcmpClient1.ReceiveTimeout:=2000;
IdIcmpClient1.Ping();
IP1IsReturn:=False;
//如有正确返回ICMP包(即能Ping通)此变量将置True.
end;
procedure TfrmPing.Timer2Timer(Sender: TObject);
//Form Create 时触发该定时器,间隔10秒触发一次。
var
IPping1:Thandle;
ThreadID1WORD;
begin
if Trim(IPadr1)<>'' then
begin
IPping1:= CreateThread(nil,0,@ICMPping1,nil,0,ThreadID1);
end;
end;
end.
整个程序是想实现一个类似于Ping命令的功能,这里仅给出了Ping 不通时出问题的关键部分,请问应如何修改才能解决该内存不能为"read"
的问题?