高手请教:把需要接收消息的过程中代码转为线程类或线程函执行(100)

  • 主题发起人 主题发起人 sjx79
  • 开始时间 开始时间
S

sjx79

Unregistered / Unconfirmed
GUEST, unregistred user!
{/* 过程声明(接收自定消息) */private Procedure OnStkDataOk(Var MyMsg: TMessage);
message WM_StkDataOK; /* End */ }Procedure TForm1.OnStkDataOk(Var MyMsg: TMessage);Var pHeader: PRCV_DATA;
pReport: PRCV_REPORT_STRUCTEx;
OneStock: RCV_REPORT_STRUCTEx;
size: integer;
nPacketNum, n: WORD;
s2: shortstring;
strmarket, ss: String;
begin
If MyMsg.wParam = 10 then
begin
pHeader := PRCV_DATA(MyMsg.lParam);
nPacketNum := pHeader^.m_nPacketNum;
pReport := pHeader^.m_pData;
Move(pReport^, OneStock, SizeOf(OneStock));
setlength(s2, 2);
Move(OneStock.m_wMarket, s2[1], 2);
If CheckBox1.Checked then
AddLog('接收到行情1 ' + s2 + pReport^.m_szLabel + ' 等' + IntToStr(nPacketNum) + '笔动态行情');
For n := 0 To nPacketNum - 1do
begin
size := OneStock.m_cbSize;
If (size > SizeOf(OneStock)) Or (size = 0) then
size := SizeOf(OneStock);
FillChar(OneStock, SizeOf(OneStock), 0);
Move(pReport^, OneStock, size);
With OneStockdo
begin
ss := DateTimeToStr(m_time / 86400 + Date1970) + ',' + m_szLabel + ',' + m_szName + ',' + FloatToStrF(m_fLastClose, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fOpen, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fHigh, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fLow, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fNewPrice, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fVolume, ffGeneral, 13, 2) + ',' + FloatToStrF(m_fAmount, ffGeneral, 13, 2);
Form1.Memo2.Lines.Add(ss);
end;
end;
end;
end;
如题,请各位高手帮忙将TForm1.OnStkDataOk 这个过程用线程来执行(最主要是for循环里的用线程来处理就可以了)注:搞定后重分感谢。
 
线程里也可以收消息的. 你搜 "线程消息".看你是收股票行情用的.你的行情源是取哪里的?
 
呵呵,你可以让主菜单接收消息,然后在消息处理里面启动一个线程,用这个线程去解决问题就可以了啊!
 
做个生产消费者队列,然后线程中等待队列中有数据,处理过程与你的消息处理过程中同,在消息处理中将每个到达的数据拷贝后加入到队列中,就完成你要的功能了。
 
Type TempTH = TThread... ... THOneStock : RCV_REPORT_STRUCTEx;
THpReport : PRCV_REPORT_STRUCTEx;
THnPacketNum : Integer;
THss : String[255];
end;
Procedure TempTH.同步;
begin
Form1.Memo2.Lines.Add(THss);
end;
Procedure TempTH.Execute;
begin
For n := 0 To THnPacketNum - 1do
begin
size := THOneStock.m_cbSize;
If (size > SizeOf(THOneStock)) Or (size = 0) then
size := SizeOf(THOneStock);
FillChar(THOneStock, SizeOf(THOneStock), 0);
Move(THpReport^, THOneStock, size);
With THOneStockdo
begin
ss := DateTimeToStr(m_time / 86400 + Date1970) + ',' + m_szLabel + ',' + m_szName + ',' + FloatToStrF(m_fLastClose, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fOpen, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fHigh, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fLow, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fNewPrice, ffGeneral, 7, 2) + ',' + FloatToStrF(m_fVolume, ffGeneral, 13, 2) + ',' + FloatToStrF(m_fAmount, ffGeneral, 13, 2);
Synt...(同步);
end;
end;
end;
pHeader := PRCV_DATA(MyMsg.lParam);
nPacketNum := pHeader^.m_nPacketNum;
pReport := pHeader^.m_pData;
With TempTH.Create(True)do
begin
Move(pReport^, THOneStock, SizeOf(OneStock));
THpReport:=pReport;
THnPacketNum := nPacketNum;
FreeOnTeminated:=True;
Resume;
end;
 
后退
顶部