C
coolingxyz
Unregistered / Unconfirmed
GUEST, unregistred user!
unit mythtead;
interface
uses
Classes, NMUDP, IniFiles, SysUtils, Forms;
type
Tmythread = class(TThread)
private
{ Private declarations }
NMUDP1 : TNMUDP;
//定义一个TNMUDP 实例
Public
{ Public declarations }
// Constructor Create(AOwner : TComponent);
Override;
protected
procedure Execute;
override;
procedure GetIni;
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure Tmythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ Tmythread }
procedure Tmythread.Execute;
var
MyData : Array[0..7] of Char;
begin
{ Place thread code here }
FreeOnTerminate := False;
//线程做完一遍后不终止
GetIni;
//NMUDP 初始化
MyData := '55410000';
NMUDP1.SendBuffer(MyData, 6);
Sleep(60000);
end;
procedure Tmythread.GetIni;
var
LPort, RPort : Integer;
WgIni: TIniFile;
begin
WgIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Wg.ini');
LPort := WgIni.ReadInteger('UDPINI','LocalPort',1025);
RPort := WgIni.ReadInteger('UDPINI','RemotePort',1024);
NMUDP1.LocalPort := LPort;
//这里出错
NMUDP1.RemotePort := RPort;
//这里出错
NMUDP1.RemoteHost :='255.255.255.255';
//这里出错
WgIni.Free;
end;
end.
我希望主程序打开后,有一个线程能每隔一分钟发一个广播包,同时有若干个客户端响应,应该怎么来设计这个程序呀。不能干扰主程序的运行。
interface
uses
Classes, NMUDP, IniFiles, SysUtils, Forms;
type
Tmythread = class(TThread)
private
{ Private declarations }
NMUDP1 : TNMUDP;
//定义一个TNMUDP 实例
Public
{ Public declarations }
// Constructor Create(AOwner : TComponent);
Override;
protected
procedure Execute;
override;
procedure GetIni;
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure Tmythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ Tmythread }
procedure Tmythread.Execute;
var
MyData : Array[0..7] of Char;
begin
{ Place thread code here }
FreeOnTerminate := False;
//线程做完一遍后不终止
GetIni;
//NMUDP 初始化
MyData := '55410000';
NMUDP1.SendBuffer(MyData, 6);
Sleep(60000);
end;
procedure Tmythread.GetIni;
var
LPort, RPort : Integer;
WgIni: TIniFile;
begin
WgIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Wg.ini');
LPort := WgIni.ReadInteger('UDPINI','LocalPort',1025);
RPort := WgIni.ReadInteger('UDPINI','RemotePort',1024);
NMUDP1.LocalPort := LPort;
//这里出错
NMUDP1.RemotePort := RPort;
//这里出错
NMUDP1.RemoteHost :='255.255.255.255';
//这里出错
WgIni.Free;
end;
end.
我希望主程序打开后,有一个线程能每隔一分钟发一个广播包,同时有若干个客户端响应,应该怎么来设计这个程序呀。不能干扰主程序的运行。