免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Delphi中多線程用消息實現(xiàn)VCL數(shù)據(jù)同步顯示
Delphi中多線程用消息實現(xiàn)VCL數(shù)據(jù)同步顯示Lanno Ckeeke 2006-5-12概述:delphi中嚴格區(qū)分主線程和子主線程,主線程負責GUI的更新,子線程負責數(shù)據(jù)運算,當數(shù)據(jù)運行完畢后,子線程可以向主線程式發(fā)送消息,以便通知其將VCL中的數(shù)據(jù)更新。實現(xiàn):關(guān)鍵在于消息的發(fā)送及接收。在消息結(jié)構(gòu)Tmessage中wParam和lParam類型為Longint,而指針類型也定義為Longint,可以通過此指針來傳遞自己所感興趣的數(shù)據(jù)。如傳遞字符數(shù)組:數(shù)組定義:              const MAX_LEN = 260;              szName : array[0..MAX_LEN] of Char; 消息發(fā)送方式:              PostMessage(Form1.Handle,WM_UPDATEDATA,Integer(PChar(@szName)),0);消息接收方式:              procedure TForm1.WMUpdateData(var msg : TMessage);begin       self.ShowData.Items.Add(PChar(msg.WParam));end;  子線程中定義兩個數(shù)據(jù)類型: public     szName : array[0..MAX_LEN] of Char;    nIndex : Integer;  完整代碼:子線程類:unit TChildThread; interface uses Classes,Messages,Windows,SysUtils;//添加的使用文件 const MAX_LEN = 260;type TChildThreads = class(TThread) private    { Private declarations } protected    procedure Execute; override; public      szName : array[0..MAX_LEN] of Char;    nIndex : Integer; end; implementationuses       Unit1; { 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 TChildThread.UpdateCaption;    begin      Form1.Caption := 'Updated in a thread';    end; } { TChildThread } procedure TChildThreads.Execute;begin { Place thread code here }   PostMessage(Form1.Handle,WM_UPDATEDATA,Integer(PChar(@szName)),0);   //注意類型轉(zhuǎn)化部分的寫法end; end. 主線程代碼:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; const       WM_UPDATEDATA = WM_USER + 100;//自定義的消息,利用此消息來實現(xiàn)對GUI的更新type TForm1 = class(TForm)    ControlPannel: TGroupBox;    StartThreads: TButton;    TabControl1: TTabControl;    SingleThread: TRadioButton;    MultipleThreads: TRadioButton;    StopThreads: TButton;    ShowData: TListBox;    ShowError: TListBox;    Initialize: TButton;Cleanup: TButton;//GUI更新的消息處理函數(shù)聲明     procedure WMUpdateData(var msg : TMessage);message WM_UPDATEDATA;    procedure StartThreadsClick(Sender: TObject); private    { Private declarations } public    { Public declarations } end; var Form1: TForm1; implementationuses       TChildThread; {$R *.dfm}//消息函數(shù)定義procedure TForm1.WMUpdateData(var msg : TMessage);begin       self.ShowData.Items.Add(PChar(msg.WParam));end; procedure TForm1.StartThreadsClick(Sender: TObject);var       oChildThread : array[0..1000] of TChildThreads; i : Integer;begin       For i := 0 to 1000 do begin     oChildThread[i] := TChildThreads.Create(true);    //向VCL中發(fā)送的數(shù)據(jù)    strcopy(@oChildThread[i].szName,PChar('Child' + IntToStr(i)));    oChildThread[i].nIndex := i;    oChildThread[i].Resume; end; end; end. 
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Delphi中的消息截獲(六種方法:Hook,SubClass,Override WndProc,Message Handler,RTTI,Form1.WindowProc:=@myfun)good
DELPHI10.2開發(fā)的跨平臺中間件
delphi基礎(chǔ)開發(fā)技巧
Delphi 中控制 Word,xml,dll 等操作
delphi 創(chuàng)建快捷方式 啟動
Windows API函數(shù)使用技巧
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服