var
i,nRet:Integer;
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
SysTime: TsystemTime;
begin
for i:=1 to strtoint(EditTimes.Text) do
begin
GetSystemTime(SysTime);
Caption:=IntToStr(SysTime.wYear)+':'+IntToStr(SysTime.wMonth)+':'+IntToStr(SysTime.wDay)+' '+IntToStr(SysTime.wHour+8)
+':'+IntToStr(SysTime.wMinute)+':'+IntToStr(SysTime.wSecond)+':'+IntToStr(SysTime.wMilliseconds);
nRet := sendMessage(inttostr(i)); if nRet > 0 then
begin
memo1.Lines.Add(Caption+' 发送成功,任务ID:'+ IntToStr(nRet));
end
else
begin
memo1.Lines.Add(Caption+' 发送失败,错误码:'+ IntToStr(nRet));
end;
end;
end;以上代码是发消息然后写日志到MEMO里,
我想学习用多线程来实现,比如新建5个线程(CreateThread)来发这个消息,这个代码要怎么改?
i,nRet:Integer;
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
SysTime: TsystemTime;
begin
for i:=1 to strtoint(EditTimes.Text) do
begin
GetSystemTime(SysTime);
Caption:=IntToStr(SysTime.wYear)+':'+IntToStr(SysTime.wMonth)+':'+IntToStr(SysTime.wDay)+' '+IntToStr(SysTime.wHour+8)
+':'+IntToStr(SysTime.wMinute)+':'+IntToStr(SysTime.wSecond)+':'+IntToStr(SysTime.wMilliseconds);
nRet := sendMessage(inttostr(i)); if nRet > 0 then
begin
memo1.Lines.Add(Caption+' 发送成功,任务ID:'+ IntToStr(nRet));
end
else
begin
memo1.Lines.Add(Caption+' 发送失败,错误码:'+ IntToStr(nRet));
end;
end;
end;以上代码是发消息然后写日志到MEMO里,
我想学习用多线程来实现,比如新建5个线程(CreateThread)来发这个消息,这个代码要怎么改?
解决方案 »
- SocketConnection连接成功标志?
- 已知道一个控件的句柄,如何获得该控件在屏幕中的绝对位置?
- 我用了一段关于建树的代码,可是老是会出现错误,有谁能帮我解释一下啊??
- 大侠们:如何通过编程方法进入到Win2000和XP的系统Ring0层内
- 请大家谈谈中国的软件行业!
- 如何使按钮的CAPTION竖排!
- 把mxOutlookBarPro2的Align设成Left,怎样点击他的item,在窗体右边出现相应的控件??
- 出点子
- 请问如何从注册表中读出DHCP是不是enable,(在window me中)?急!
- 用 CreateOleObject 创建的对象怎么释放?请高手帮忙
- 请问: .cancel和.cancelupdates有什么不同?
- 转换函数
var
i,nRet:Integer;
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
SysTime: TsystemTime;
Caption:string;
begin
for i:=1 to strtoint(EditTimes.Text) do
begin
GetSystemTime(SysTime);
Caption:=IntToStr(SysTime.wYear)+':'+IntToStr(SysTime.wMonth)+':'+IntToStr(SysTime.wDay)+' '+IntToStr(SysTime.wHour+8)
+':'+IntToStr(SysTime.wMinute)+':'+IntToStr(SysTime.wSecond)+':'+IntToStr(SysTime.wMilliseconds);
nRet := sendMessage(inttostr(i)); if nRet > 0 then
begin
memo1.Lines.Add(Caption+' 发送成功,任务ID:'+ IntToStr(nRet));
end
else
begin
memo1.Lines.Add(Caption+' 发送失败,错误码:'+ IntToStr(nRet));
end;
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
CThread:Thandle;//声明了一个句柄
Tid:DWord;
i:integer;
begin
for i:=0 to strtoint(EditThread.Text)-1 do
Cthread:=CreateThread(nil,0,@SendThread,nil,0,Tid); //创建一个线程,同时调用线程函数end;