| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> delphi >> WIN32 xia DELPHI zhong de duo xian cheng 【 shen ru VCL yuan ma 】( yi )

WIN32 xia DELPHI zhong de duo xian cheng 【 shen ru VCL yuan ma 】( yi )

2006-12-12 19:18:04 编辑來源:互联网 评论
 
 
 
本文为【WIN32下DELPHI中的多线程【深入VCL源码】(一)】的拼音翻译版
  xian cheng de ji chu zhi shi
   xian cheng de zu cheng 。 xian cheng you liang bu fen zu cheng 。
   1、 yi ge shi xian cheng de nei gai dui xiang , cao zuo xi tong yong ta lai dui xian cheng shi shi guan li 。 nei gai dui xiang ye shi xi tong yong lai cun fang xian cheng tong ji xin xi de di fang 。
   2、 ling yi ge shi xian cheng dui zhan , ta yong yu wei hu xian cheng zai zhi xing dai ma shi xu yao de suo you han shu shen shu he ju bu bian liang 。
   jin cheng cong lai bu zhi xing ren he dong xi , ta zhi shi xian cheng de rong qi 。 xian cheng zong shi zai mou ge jin cheng huan jing zhong chuang jian de , er qie ta de zheng ge shou ming qi dou zai gai jin cheng zhong 。 zhe yi wei zhe xian cheng zai ta de jin cheng di zhi kong jian zhong zhi xing dai ma , bing qie zai jin cheng de di zhi kong jian zhong dui shu ju jin xing cao zuo 。 yin ci , ru guo zai dan jin cheng huan jing zhong , ni you liang ge huo duo ge xian cheng zheng zai yun xing , na me zhe liang ge xian cheng jiang gong xiang dan ge di zhi kong jian 。 zhe xie xian cheng neng gou zhi xing xiang tong de dai ma , dui xiang tong de shu ju jin xing cao zuo 。 zhe xie xian cheng huan neng gong xiang nei gai dui xiang ju bing , yin wei ju bing biao yi lai yu mei ge jin cheng er bu shi mei ge xian cheng cun zai 。
   xian cheng shi yi zhong cao zuo xi tong dui xiang , ta biao shi zai jin cheng zhong dai ma de yi tiao zhi xing lu jing 。 zai mei yi ge Wi n32 de ying yong cheng xu zhong dou zhi shao you yi ge xian cheng , ta tong chang bei cheng wei zhu xian cheng huo mo ren xian cheng 。 zai ying yong cheng xu zhong ye ke yi zi you di chuang jian bie de xian cheng qu zhi xing qi ta ren wu 。 xian cheng ji shu shi bu tong de dai ma ke yi tong shi yun xing 。 dang ran , zhi you zai duo C P U de ji suan ji shang , duo ge xian cheng cai neng gou zhen zheng di tong shi yun xing 。 zai dan ge CPU shang , you yu cao zuo xi tong ba C P U de shi jian fen cheng hen duan de pian duan fen pei gei mei ge xian cheng , zhe yang gei ren de gan jiao hao xiang shi duo ge xian cheng zhen de tong shi yun xing , ta men zhi shi “ kan qi lai ” tong shi zai yun xing 。
   Win32 shi yi zhong qiang zhan shi cao zuo xi tong , cao zuo xi tong fu ze guan li na ge xian cheng zai shen me shi hou zhi xing 。 ru guo dang xian cheng 1 zan ting zhi xing shi , xian cheng 2 cai you ji hui huo de C P U shi jian , wo men shuo xian cheng 1 shi qiang zhan de 。 ru guo mou ge xian cheng de dai ma xian ru si xun huan , zhe bing bu ke pa , cao zuo xi tong reng hui an pai shi jian gei qi ta xian cheng 。
   chuang jian yi ge xian cheng
   zhu yi : mei ge xian cheng bi xu yong you yi ge jin ru dian han shu , xian cheng cong zhe ge jin ru dian kai shi yun xing 。 xian cheng han shu ke yi shi yong ren he he fa de ming zi 。 ke yi gei xian cheng han shu chuan di dan ge shen shu , shen shu de han yi you ni zi ji ding yi 。 xian cheng han shu bi xu you yi ge fan hui zhi , ta jiang cheng wei gai xian cheng de tui chu dai ma 。 xian cheng han shu ying gai jin ke neng de shi yong han shu shen shu he ju bu bian liang 。 xian cheng han shu lei si xia mian de yang zi (Object Pascal):
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// zhu yi zui hou de stdcall, hou mian wo hui miao shu yi xie you yong de dong xi
WIN32下DELPHI中的多线程【深入VCL源码】(一)
function MyThread(info : Pointer):DWORD; stdcall;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
i : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
for i := 0 to Pinfo(info)^.count-1 do
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Form1.Canvas.TextOut(Pinfo(info)^.x,Pinfo(info)^.y,inttostr(i));
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Result := 0;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
   shang mian de de dai ma gong neng hen jian dan , ni ke yi zai cheng xu zhong zhi jie tiao yong , li ru zhe yang :
WIN32下DELPHI中的多线程【深入VCL源码】(一)
type
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Tinfo = record
WIN32下DELPHI中的多线程【深入VCL源码】(一)
count : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
x : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
y : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Pinfo= ^Tinfo;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure TForm1.Button4Click(Sender: TObject);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi : Pinfo;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi :=AllocMem(sizeof(tinfo));
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi^.count := 1000000;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi^.x := 100;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi^.y := 400;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
MyThread(ppi);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
   dang ni zai yi ge chuang kou zhong yong zhe yang de fang shi tiao yong shi , ni hui fa xian zai zhi xing de guo cheng zhong , ni jiang wu fa zai chuang kou shang jin xing qi ta cao zuo , yin wei ta gong zuo yu ni cheng xu de zhu xian cheng zhi zhong 。 ru guo ci shi , ni huan xi wang chuang kou ke yi jin xing qi ta cao zuo 。 zen me ban ? rang ta zai hou tai gong zuo , rang ta cheng wei ling yi ge xian cheng , shi de bu tong de dai ma ke yi tong shi yun xing 。
   zuo fa hen jian dan , ru guo xiang yao chuang jian yi ge huo duo ge fu zhu xian cheng , zhi xu yao rang yi ge yi jing zai yun xing de xian cheng lai tiao yong CreateThread, yuan xing ru xia :
WIN32下DELPHI中的多线程【深入VCL源码】(一)
HANDLE CreateThread(
WIN32下DELPHI中的多线程【深入VCL源码】(一)
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes
WIN32下DELPHI中的多线程【深入VCL源码】(一)
DWORD dwStackSize, // initial thread stack size, in bytes
WIN32下DELPHI中的多线程【深入VCL源码】(一)
LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function
WIN32下DELPHI中的多线程【深入VCL源码】(一)
LPVOID lpParameter, // argument for new thread
WIN32下DELPHI中的多线程【深入VCL源码】(一)
DWORD dwCreationFlags, // creation flags
WIN32下DELPHI中的多线程【深入VCL源码】(一)
LPDWORD lpThreadId // pointer to returned thread identifier
WIN32下DELPHI中的多线程【深入VCL源码】(一)
);
   dang CreateThread, bei tiao yong shi , xi tong chuang jian yi ge xian cheng nei gai dui xiang 。 gai xian cheng nei gai dui xiang bu shi xian cheng ben shen , er shi cao zuo xi tong yong lai guan li xian cheng de jiao xiao de shu ju jie gou 。 ke yi jiang xian cheng nei gai dui xiang shi wei you guan yu xian cheng de tong ji xin xi zu cheng de yi ge xiao xing shu ju jie gou 。 xi tong cong jin cheng de di zhi kong jian zhong fen pei nei cun , gong xian cheng de dui zhan shi yong 。 xin xian cheng yun xing de jin cheng huan jing yu chuang jian xian cheng de huan jing xiang tong 。 yin ci , xin xian cheng ke yi fang wen jin cheng de nei gai dui xiang de suo you ju bing 、 jin cheng zhong de suo you nei cun he zai zhe ge xiang tong de jin cheng zhong de suo you qi ta xian cheng de dui zhan 。 zhe shi de dan ge jin cheng zhong de duo ge xian cheng que shi neng gou fei chang rong yi di hu xiang tong xin 。
   xia mian lai shuo zhe ge han shu de ji ge shen shu :
   1、psa ci shen shu shi zhi xiang SECURITY_ATTRIBUTES jie gou de zhi zhen 。 ru guo xiang yao gai xian cheng nei gai dui xiang de mo ren an quan shu xing , ke yi ( bing qie tong chang neng gou ) chuan di NULL。 ru guo xi wang suo you de zi jin cheng neng gou ji cheng gai xian cheng dui xiang de ju bing , bi xu she ding yi ge SECURITY_ATTRIBUTES jie gou , ta de bInheritHandle( shi fou ke ji cheng ) cheng yuan bei chu shi hua wei True, guan yu SECURITY_ATTRIBUTES, yin wei ci wen de mu de bu shi jie shao ta , suo yi zhe li bu zuo xiang xi jie shao , ju ti ke yi shen kao MSDN。 tong chang shi yong , wo men chuan di null jiu gou le 。
   2、cbStack yong yu she ding xian cheng ke yi jiang duo shao di zhi kong jian yong yu ta zi ji de dui zhan 。 dang tiao yong CrateThread shi , ru guo chuan di de zhi bu shi 0, jiu neng shi gai han shu jiang suo you de cun chu qi bao liu bing fen pei gei xian cheng de dui zhan 。 you yu suo you de cun chu qi yu xian zuo le fen pei , yin ci ke yi que bao xian cheng yong you zhi ding rong liang de ke yong dui zhan cun chu qi 。 tong chang zhuang kuang xia , wo men hui she zhi wei 0。
   3、pfnStartAddr and pvParam,pfnStartAddr shen shu yong yu zhi ming xiang yao xin xian cheng zhi xing de xian cheng han shu de di zhi 。 xian cheng han shu de pvParam shen shu yu yuan xian chuan di gei CreateThread de pvParam shen shu shi xiang tong de 。CreateThread shi yong gai shen shu bu zuo bie de shi qing , zhi shi zai xian cheng qi dong zhi xing shi jiang gai shen shu chuan di gei xian cheng han shu 。 gai shen shu ti gong le yi ge jiang chu shi hua zhi chuan di gei xian cheng han shu de shou duan 。 gai chu shi hua shu ju ji ke yi shi shu zi zhi , ye ke yi shi zhi xiang bao han qi ta xin xi de yi ge shu ju jie gou de zhi zhen 。 ci shi hui tou zai qu kan wo shang mian li zi shang de MyThread, ni hui fa xian ta you yi ge wu lei xing de zhi zhen shen shu ( yong C lai miao shu , ying gai shi PVOID), zai chuang jian xian cheng shi , zhe ge shen shu jiu tong guo pvParam lai fu zhi 。
   4、fdwcreate ci shen shu ke yi she ding yong yu kong zhi chuang jian xian cheng de qi ta biao zhi 。 ta ke yi shi liang ge zhi zhong de yi ge 。 ru guo gai zhi shi 0, na me xian cheng chuang jian hou ke yi li ji jin xing tiao du 。 ru guo gai zhi shi CREATE_ SUSPENDED, xi tong ke yi wan zheng di chuang jian xian cheng bing dui ta jin xing chu shi hua , dan shi yao zan ting gai xian cheng de yun xing , zhe yang ta jiu wu fa jin xing tiao du 。 zai DELPHI de WINDOWS.PAS dan yuan , ni ke yi fa xian ta de ding yi
  CREATE_SUSPENDED= $00000004;
   5、pdwThreadId zui hou yi ge shen shu bi xu shi Dword de yi ge you xiao di zhi ,CreateThread
  shi yong zhe ge di zhi lai cun fang xi tong fen pei gei xin xian cheng de ID.
   you le shang mian zhe xie ji chu , xia mian wo men jiu shi yong createThread lai chuang jian gang cai na ge MyThread xian cheng (DELPHI7);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// yi ge zi ding yi lei xing
WIN32下DELPHI中的多线程【深入VCL源码】(一)
type
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Tinfo = record
WIN32下DELPHI中的多线程【深入VCL源码】(一)
count : integer;// ji shu qi ge shu
WIN32下DELPHI中的多线程【深入VCL源码】(一)
x : integer;// yao xian shi zai chuang ti shang wei zhi de heng zuo biao
WIN32下DELPHI中的多线程【深入VCL源码】(一)
y : integer;// zong zuo biao
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Pinfo=^Tinfo;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
MyThreadHad : THandle;// yi ge quan ju bian liang , yong lai jie shou CreateThread chuang jian xin xian cheng de ju bing
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure TForm1.Button4Click(Sender: TObject);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi : Pinfo;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
MyThreadId : DWORD;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{ fen pei kong jian , zhu yi , yin wei zhe li wo zhi shi yi ge yong lai yan shi CreateThread shi yong de dai ma , suo yi mei you shi fang pp, dan you xiu de dai ma zui hou ji de fen pei le kong jian yi ding yao shi fang }
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi :=AllocMem(sizeof(tinfo));
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// chu shi hua
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi^.count := 100000;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi^.x := 100;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ppi^.y := 400;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// xia mian zhe xing dai ma shi guan jian
WIN32下DELPHI中的多线程【深入VCL源码】(一)
MyThreadHad := CreateThread(nil,0,@MyThread,ppi,0,MyThreadId);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

   zhi xing ci duan dai ma , ni hui fa xian , ta yi ran hui zai ping mu zhi ding qu yu shu chu wen zi , he zui kai shi shi wo men yong ba MyThread zai zhu xian cheng zhong yun xing bu tong de shi , ci shi , ni yi ran ke yi dui chuang kou jin xing qi ta cao zuo 。
   kan dai ma de zui hou yi xing , ta shi yong le createThread, kan ta de shen shu , di yi ge nil yi ji di er ge 0 yi wai zhe , ta shi yong mo ren de an quan she zhi yi ji mo ren de xian cheng dui zhan da xiao , di san ge shen shu shi MyThread de di zhi ( zhu yi @ fu hao ), ran hou wo men chuan di le ppi zhe ge Pinfo lei xing de zhi zhen , shi de xian cheng han shu jie shou yi ge shen shu , ru guo ni bu zhun bei rang xian cheng jie shou zhe ge shen shu , yong nil,fdwcreate shen shu , wo men fu zhi wei 0, yi wei zhe wo men xi wang xian cheng li ji zhi xing , zui hou yi ge shen shu yong lai jie shou xin xian cheng de ID。
  rang wo men lai kan kan CreateThread dou gan le xie shen me 。
WIN32下DELPHI中的多线程【深入VCL源码】(一)

   shang tu xian shi le xi tong zai chuang jian xian cheng he dui xian cheng jin xing chu shi hua shi bi xu zuo xie shen me gong zuo 。 tiao yong CreateThread ke shi xi tong chuang jian yi ge xian cheng nei gai dui xiang 。 gai dui xiang de chu shi shi yong ji shu shi 2( zai xian cheng ting zhi yun xing he cong CreateThread fan hui de ju bing guan bi zhi qian , xian cheng nei gai dui xiang bu hui bei che xiao )。 xian cheng de nei gai dui xiang de qi ta shu xing ye bei chu shi hua , zan ting ji shu bei she zhi wei 1, tui chu dai ma shi zhong wei STILL_ACTIVE(0 x 1 0 3), gai dui xiang she zhi wei wei tong zhi zhuang tai 。
   yi dan nei gai dui xiang chuang jian wan cheng , xi tong jiu fen pei yong yu xian cheng de dui zhan de nei cun 。 gai nei cun shi cong jin cheng de di zhi kong jian fen pei er lai de , yin wei xian cheng bing bu yong you ta zi ji de di zhi kong jian 。 ran hou xi tong jiang liang ge zhi xie ru xin xian cheng de dui zhan de shang duan ( xian cheng dui zhan zong shi cong nei cun de gao di zhi xiang di di zhi jian li )。 xie ru dui zhan de di yi ge zhi shi chuan di gei CreateThread de pvParam shen shu de zhi 。 jin kao ta de xia mian shi chuan di gei CreateThread de pfnStartAddr shen shu de zhi 。 mei ge xian cheng dou you ta zi ji de yi zu C P U ji cun qi , cheng wei xian cheng de shang xia wen 。 gai shang xia wen fan yang le xian cheng shang ci yun xing shi gai xian cheng de CPU ji cun qi de zhuang tai 。 xian cheng de zhe zu C P U ji cun qi bao cun zai yi ge CONTEXT jie gou 。CONTEXT jie gou ben shen ze bao han zai xian cheng de nei gai dui xiang zhong 。
   zhi ling zhi zhen he dui zhan zhi zhen ji cun qi shi xian cheng shang xia wen zhong liang ge zui chong yao de ji cun qi 。 xian cheng zong shi zai jin cheng de shang xia wen zhong yun xing de 。 yin ci , zhe xie di zhi dou yong yu biao shi yong you xian cheng de jin cheng di zhi kong jian zhong de nei cun 。 dang xian cheng de nei gai dui xiang bei chu shi hua shi ,CONTEXT jie gou de dui zhan zhi zhen ji cun qi bei she zhi wei xian cheng dui zhan shang yong lai fang zhi pfnStartAddr de di zhi 。 dang xian cheng wan quan chu shi hua hou , xi tong jiu yao cha kan CREATE_SUSPENDED biao zhi shi fou yi jing chuan di gei CreateThread。 ru guo gai biao zhi mei you chuan di , xi tong bian jiang xian cheng de zan ting ji shu di jian wei 0, gai xian cheng ke yi tiao du dao yi ge jin cheng zhong 。 ran hou xi tong yong shang ci bao cun zai xian cheng shang xia wen zhong de zhi jia zai dao shi ji de C P U ji cun qi zhong 。 zhe shi xian cheng jiu ke yi zhi xing dai ma , bing dui ta de jin cheng de di zhi kong jian zhong de shu ju jin xing cao zuo 。
   zai zhe li , wo huan yao jian dan de miao shu yi xia CONTEXT jie gou , yin wei WIN32 shi qiang zhan shi cao zuo xi tong , yi ge xian cheng ji hu bu ke neng yong yuan de zhan ju CPU, ye jiu shi shuo , ta hui zai yi ding shi jian hou ( zai WINDOWS zhong , da gai shi 20ms de shi jian ), bei CPU fang zai yi bian , yi duan shi jian zhi hou , cai ke yi chong xin huo de CPU shi jian pian , ci shi jiu you yi ge wen ti , xian cheng xian zai zhi xing dao le na li ,CPU zai zai ci fen pei gei ta shi jian pian zhi xing de shi hou , bi xu zhi dao zhe xie xin xi , nan dao yao cong 0 kai shi ma ?CONTEXT jie gou de zuo yong jiu shi yong lai jie jue zhe ge wen ti 。
   zai Platform SDK zhong , ni ke yi kan dao xia mian de xin xi :
   “CONTEXT jie gou bao han le te ding chu li qi de ji cun qi shu ju 。 xi tong shi yong CONTEXT jie gou zhi xing ge zhong nei bu cao zuo 。 mu qian , yi jing cun zai wei Intel、MIPS、Alpha he PowerPC chu li qi ding yi de CONTEXT jie gou 。 ruo yao le jie zhe xie jie gou de ding yi , shen jian tou wen jian WinNT.h”。
   gai wen dang bing mei you shuo ming gai jie gou de cheng yuan , ye mei you miao shu zhe xie cheng yuan shi shui , yin wei zhe xie cheng yuan yao qu jue yu Windows zai na ge CPU shang yun xing 。 shi ji shang , zai Windows ding yi de suo you shu ju jie gou zhong ,CONTEXT jie gou shi te ding yu CPU de wei yi shu ju jie gou 。 na me CONTEXT jie gou zhong jiu jing cun zai na xie dong xi ne ? ta bao han le zhu ji C P U shang de mei ge ji cun qi de shu ju jie gou 。 zai x86 ji suan ji shang , shu ju cheng yuan shi Eax、Ebx、Ecx、Edx deng deng 。 ru guo shi Alpha chu li qi , na me shu ju cheng yuan bao kuo IntV0、IntT0、IntT1、IntS0、In tRa he IntZero deng deng 。
   Windows shi ji shang yuan xu cha kan xian cheng nei gai dui xiang de nei bu qing kuang , yi bian zhua qu ta dang qian de yi zu CPU ji cun qi 。 ruo yao jin xing zhe xiang cao zuo , zhi xu yao tiao yong GetThreadContext han shu 。 guan yu ci han shu de shi yong , wo men xia ci zai shuo 。
  xian cheng de zhong zhi
   zhong zhi yi ge xian cheng de yun xing , you 4 ge fang fa :
   1、 xian cheng han shu fan hui , zhe shi zui hao de
   2、 tiao yong ExitThread han shu , xian cheng jiang zi dong che xiao
   3、 tiao yong TerminateThread han shu
   4、 bao han xian cheng de jin cheng zhong zhi yun xing
  xian cheng han shu fan hui
   shi zhong dou ying gai jiang xian cheng she ji cheng zhe yang de xing shi , ji dang xiang yao xian cheng zhong zhi yun xing shi , ta men jiu neng gou fan hui 。 zhe shi que bao suo you xian cheng zi yuan bei zheng que di qing chu de wei yi ban fa 。 ru guo
  xian cheng neng gou fan hui , jiu ke yi que bao xia lie shi xiang de shi xian :
  • zai xian cheng han shu zhong chuang jian de suo you C + + dui xiang yun jiang tong guo ta men de che xiao han shu zheng que di che xiao 。
  • cao zuo xi tong jiang zheng que di shi fang xian cheng dui zhan shi yong de nei cun 。
  • xi tong jiang xian cheng de tui chu dai ma ( zai xian cheng de nei gai dui xiang zhong wei hu ) she zhi wei xian cheng han shu de fan hui zhi 。
  • xi tong jiang di jian xian cheng nei gai dui xiang de shi yong ji shu 。
  tiao yong Exitthread han shu
  void ExitThread(DWORD dwExitCode);
   gai han shu jiang zhong zhi xian cheng de yun xing , bing dao zhi cao zuo xi tong qing chu gai xian cheng shi yong de suo you cao zuo xi tong zi yuan 。 dan shi cheng xu zhong yong dao de zi yuan ( li ru DELPHI lei dui xiang ) jiang bu bei che xiao 。
  tiao yong TerminateThread han shu
  Bool TerminateThread(HANDLE hThread,DWORD dwExitCode);
   guan chan zhe ge han shu he ExitThread de qu bie , ni hui fa xian ta chu le you dwExitCode zhe ge tui chu ma shen shu zhi wai , huan bao han le ke zhi ding xian cheng de ju bing shen shu 。 kan dao zhe li ni jiu ying gai hui xiang dao liang zhe de qu bie ,Exitthread zong shi che xiao tiao yong de xian cheng , er TerminateThread neng gou che xiao ren he xian cheng 。hThread shen shu yong yu biao shi bei zhong zhi yun xing de xian cheng de ju bing 。 dang xian cheng zhong zhi yun xing shi , ta de tui chu dai ma cheng wei ni zuo wei dwExitCode shen shu chuan di de zhi 。 tong shi , xian cheng de nei gai dui xiang de shi yong ji shu ye bei di jian 。 zhi de zhu yi de shi , ci han shu shi yi bu yun xing de han shu , ye jiu shi shuo , ta gao su xi tong ni xiang yao xian cheng zhong zhi yun xing , dan shi , dang han shu fan hui shi , bu neng bao zheng xian cheng bei che xiao 。 ru guo xu yao que qie di zhi dao gai xian cheng yi jing zhong zhi yun xing , bi xu tiao yong WaitForSingleObject huo zhe lei si de han shu , chuan di xian cheng de ju bing 。
  zai jin cheng zhong zhi shi che xiao xian cheng
   zhe shi hen rong yi xiang dao de 。 wu xu guo duo jie shi 。
  xian cheng zhong zhi shi fa sheng de cao zuo
  dang xian cheng zhong zhi yun xing shi , hui fa sheng xia lie cao zuo :
  • xian cheng yong you de suo you yong hu dui xiang yun bei shi fang 。 zai Windows zhong , da duo shu dui xiang shi you bao han chuang jian zhe xie dui xiang de xian cheng de jin cheng yong you de 。 dan shi yi ge xian cheng yong you liang ge yong hu dui xiang , ji chuang kou he gua gou 。 dang xian cheng zhong zhi yun xing shi , xi tong hui zi dong che xiao ren he chuang kou , bing qie xie zai xian cheng chuang jian de huo an zhuang de ren he gua gou 。 qi ta dui xiang zhi you zai yong you xian cheng de jin cheng zhong zhi yun xing shi cai bei che xiao 。
  • xian cheng de tui chu dai ma cong STILL_ACTIVE gai wei chuan di gei ExitThread huo TerminateThread de dai ma
  • xian cheng nei gai dui xiang de zhuang tai bian wei yi tong zhi 。
  • ru guo xian cheng shi jin cheng zhong zui hou yi ge huo dong xian cheng , xi tong ye jiang jin cheng shi wei yi jing zhong zhi yun xing 。
  • xian cheng nei gai dui xiang de shi yong ji shu di jian 1。 dang yi ge xian cheng zhong zhi yun xing shi , zai yu ta xiang guan lian de xian cheng nei gai dui xiang de suo you wei jie shu de yin yong guan bi zhi qian , gai nei gai dui xiang bu hui zi dong bei shi fang 。
   yi dan xian cheng bu zai yun xing , xi tong zhong jiu mei you bie de xian cheng neng gou chu li gai xian cheng de ju bing 。 ran er bie de xian cheng ke yi tiao yong GetExitcodeThread lai jian cha you hThread biao shi de xian cheng shi fou yi jing zhong zhi yun xing 。 ru guo ta yi jing zhong zhi yun xing , ze que ding ta de tui chu dai ma .
   BOOL GetExitcodeThread(HANDLE hThread,PDWORD pdwExitcode);
   tui chu dai ma de zhi zai pdwExitcode); zhi xiang de DWORD zhong fan hui 。 ru guo tiao yong GetExitcodeThread shi xian cheng shang wei zhong zhi yun xing , gai han shu jiu yong STILL_ACTIVE biao shi fu ( ding yi wei 0x103) tian ru DWORD。 ru guo gai han shu yun xing cheng gong , bian fan hui T R U E。
   shang mian miao shu le jie shu xian cheng de duo zhong ban fa , zhe li bi xu shuo ming yi dian , ru guo you ke neng , na jin liang shi yong di yi zhong fang shi lai jie shu xian cheng , ta ke yi que bao ni shi fang le suo you de zi yuan 。 hao de cheng xu ying gai jin ke neng de jian shao dui ke hu zi yuan de lang fei 。
  stdcall
   zhun que de shuo ,stdcall zhe ge biao shi fu ben lai he xian cheng mei you zhi jie de lian xi , dan yin wei wo zhe li de shi li dai ma shi yong Object Pascal xie de , er wo men tiao yong de CreateThread ze shi yong c shi xian de , zhe liang zhong yu yan de han shu ru zhan de fang shi shi bu tong de ,pascal shi cong zuo dao you 。 jia shang stdcall, ke yi shi de ru zhan fang shi gai wei cong you dao zuo yi fu he bie de yu yan de xi guan 。 wo men shang mian tiao yong createThread han shu shi , yin wei wo chuan di le na ge wu lei xing de zhi zhen shen shu , suo yi , bi xu jia shang stdcall zhi ming ru zhan fang shi , fou ze hui chu xian di zhi fang wen cuo wu 。 dang ran , ru guo ni bing bu jue ding chuan di shen shu , ni ye ke yi bu shi yong stdcall。 bu guo zuo wei yi zhong hao de bian ma xi guan , ni zui hao huan shi jia shang 。
  DELPHI zhong chuang jian xian cheng
   ru guo ni zhi xiang zuo yi ge dai ma ban yun gong , ni wan quan ke yi bu le jie shang mian de nei rong , dan ru guo ni xiang cheng wei yi ge he ge de WIN32 cheng xu yuan , shen ru zhe xie nei rong , bi ni fu qian de duo xue yi men yu yan you yong 。
   DELPHI ba you guan xian cheng de API feng zhuang zai TThread zhe ge Object Pascal de dui xiang zhong 。 jie he shang mian de nei rong , xian qu kan TThread yuan ma
WIN32下DELPHI中的多线程【深入VCL源码】(一)
TThread = class
WIN32下DELPHI中的多线程【深入VCL源码】(一)
private
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF MSWINDOWS}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FHandle: THandle;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FThreadID: THandle;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF LINUX}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// ** FThreadID is not THandle in Linux **
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FThreadID: Cardinal;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FCreateSuspendedSem: TSemaphore;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FInitialSuspendDone: Boolean;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FCreateSuspended: Boolean;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FTerminated: Boolean;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FSuspended: Boolean;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FFreeOnTerminate: Boolean;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FFinished: Boolean;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FReturnValue: Integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FOnTerminate: TNotifyEvent;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FSynchronize: TSynchronizeRecord;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FFatalException: TObject;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure CallOnTerminate;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
class procedure Synchronize(ASyncRec: PSynchronizeRecord); overload;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF MSWINDOWS}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
function GetPriority: TThreadPriority;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure SetPriority(Value: TThreadPriority);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF LINUX}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// ** Priority is an Integer value in Linux
WIN32下DELPHI中的多线程【深入VCL源码】(一)
function GetPriority: Integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure SetPriority(Value: Integer);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
function GetPolicy: Integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure SetPolicy(Value: Integer);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure SetSuspended(Value: Boolean);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
protected
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure CheckThreadError(ErrCode: Integer); overload;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure CheckThreadError(Success: Boolean); overload;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure DoTerminate; virtual;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Execute; virtual; abstract;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Synchronize(Method: TThreadMethod); overload;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property ReturnValue: Integer read FReturnValue write FReturnValue;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property Terminated: Boolean read FTerminated;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
public
WIN32下DELPHI中的多线程【深入VCL源码】(一)
constructor Create(CreateSuspended: Boolean);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
destructor Destroy; override;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure AfterConstruction; override;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Resume;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Suspend;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Terminate;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
function WaitFor: LongWord;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
class procedure Synchronize(AThread: TThread; AMethod: TThreadMethod); overload;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
class procedure StaticSynchronize(AThread: TThread; AMethod: TThreadMethod);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property FatalException: TObject read FFatalException;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property FreeOnTerminate: Boolean read FFreeOnTerminate write FFreeOnTerminate;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF MSWINDOWS}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property Handle: THandle read FHandle;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property Priority: TThreadPriority read GetPriority write SetPriority;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF LINUX}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// ** Priority is an Integer **
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property Priority: Integer read GetPriority write SetPriority;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property Policy: Integer read GetPolicy write SetPolicy;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property Suspended: Boolean read FSuspended write SetSuspended;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF MSWINDOWS}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property ThreadID: THandle read FThreadID;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$IFDEF LINUX}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// ** ThreadId is Cardinal **
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property ThreadID: Cardinal read FThreadID;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{$ENDIF}
WIN32下DELPHI中的多线程【深入VCL源码】(一)
property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
   cong TThread de sheng ming zhong ke yi kan chu , ta ding yi le Windows he Linux xia fen bie yao wan cheng de cao zuo , zhe li wo men zhi tan WIN32,TThread zhi jie cong TObject ji cheng , yin wei , ta bu shi zu jian 。 ni huan ke yi kan dao ta you yi ge Execute de fang fa
   procedure Execute; virtual; abstract;
   bing qie ni ke yi kan dao , ta shi chou xiang de , yin wei , bu neng chuang jian TThread de shi li , ni zhi neng chuang jian ta de pai sheng lei de shi li 。 zai qu kan kan ta de gou zao han shu , ni hui kan dao zhe yang yi ju dai ma
   FHandle := BeginThread(nil, 0, @ThreadProc, Pointer(Self), CREATE_SUSPENDED, FThreadID); zai shen ru qu kan zhe ge BeginThread,
   Result := CreateThread(SecurityAttributes, StackSize, @ThreadWrapper, P,CreationFlags, ThreadID); ni kan dao le shen me ? shi de ,CreateThread, jie he zhe liang ju , kan kan ta dou gan le xie shen me , mo ren de an quan shu xing , mo ren de dui zhan da xiao , yi ge ru kou di zhi , yi ge shen shu , yi ge chuang jian biao zhi , huan you yi ge threadid。 ni he ben wen zui kai shi de na xie nei rong dui shang le ma ? wo men you kan dao ta chuan di de xian cheng han shu shi ThreadProc, zai qu kan kan ta 。 xia mian zhi tie le yi xie he ben wen you guan xi de dai ma
WIN32下DELPHI中的多线程【深入VCL源码】(一)
try
WIN32下DELPHI中的多线程【深入VCL源码】(一)
if not Thread.Terminated then
WIN32下DELPHI中的多线程【深入VCL源码】(一)
try
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Thread.Execute;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
except
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Thread.FFatalException := AcquireExceptionObject;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
finally
   ta shou xian gen ju TThread lei zhong de yi ge shu xing Terminated( bu er lei xing ) lai pan duan xian cheng de zhuang tai , ru guo ni mei you tong guo wai bu dai ma jiang Terminated shen zhi wei true, ta jiang hui zhi xing Execute( zhu yi zhe ge fang fa , wo men gang cai ti dao guo ta shi yi ge chou xiang de , ni bi xu rang ta gan dian shen me , ye jiu shi shuo ,Tthread.execute jiang shi ni de xian cheng jiang yao zhi xing de cao zuo )。 ran hou shi yi chang de chu li 。 ni shi fou dui DELPHI de TThread you dian le jie le ne ? ru guo you xing qu , hao hao kan kan ta de yuan ma ba 。
   shuo dao zhe li ,DELPHI zhong TThread chuang jian yi ge xian cheng de ji ben liu cheng jiu chu lai le 。 tiao yong zi ji de gou zao han shu , chuan di yi ge bu er lei xing de bian liang , zhe ge bian liang dui ying CreateThread han shu de fdwcreate shen shu , yong lai jue ding xian cheng shi li ji zhi xing huan shi gua qi , gou zao han shu you tiao yong le yi ge BeginThread, er zheng shi zhe ge BeginThread tiao yong le WIN API CreateThread, ta jiang yi ge ThreadProc xian cheng han shu chuan di gei CreateThread, er zhe ge ThreadProc ze tiao yong ni bi xu fu gai de fang fa Execute lai wan cheng ni xiang yao jin xing de cao zuo 。
   zai lai kan kan ta de zhong zhi , ji xu gang cai de nei rong , kan ThreadProc zhe ge han shu de xia mian dai ma , ni hui fa xian , dang Execute zhi xing wan bi zhi hou , ta jiu ren wei zhe ge xian cheng zhong zhi le , ta tiao yong le EndThread(Result), ran hou zhe ge EndThread you tiao yong le ExitThread(ExitCode)。 dang jie shu shi yong TThread dui xiang shi , ying gai que bao yi jing ba zhe ge Object Pascal dui xiang cong nei cun zhong qing chu le 。 zhe cai neng que bao suo you nei cun zhan you dou shi fang diao 。 jin guan zai jin cheng zhong zhi shi hui zi dong qing chu suo you de xian cheng dui xiang , dan ji shi qing chu yi bu zai yong de dui xiang , ke yi shi nei cun de shi yong xiao lv ti gao 。 huan shi ThreadProc de yuan ma , ni hui fa xian dang xian cheng de Execute zhi xing wan zhi hou , ta yao gen Thread.FFreeOnTerminate lai jue ding shi fou shi fang zi yuan 。FreeThread := Thread.FFreeOnTerminate;...if FreeThread then Thread.Free; zhe shi fei chang hao de , ye jiu shi shuo , ni ke yi tong guo zai dui FreeOnTerminate zhe ge shu xing fu zhi wei true( guan cha ta de yuan ma ,FreeOnTerminate shi FFreeOnTerminate zhe ge si you bian liang de fang wen qi ), lai rang TThread dui xiang zi dong zai xian cheng zhi xing wan bi zhi hou zi dong shi fang zi yuan 。
   kan le zhe me duo , wo men ke yi shu li yi xia si lu le , shi yong TThread dui xiang , wo men bi xu cong ta pai sheng yi ge lei , ran hou ni bi xu fu gai Execute zhe ge fang fa , zai zhe li , wan cheng ni yao rang xian cheng zuo de shi qing 。 ru guo you ke neng ( huo zhe shuo jin liang , chu fei ni dui zhe ge xian cheng huan you bie de xu qiu ), huan ke yi zai zhe li tong guo she zhi FreeOnTerminate := true, shi de xian cheng zai zhi xing wan bi zhi hou zi dong shi fang zi yuan 。 wo men ke yi tong guo TThread dui xiang gou zao han shu de shen shu lai jue ding xian cheng shi fou li ji yun xing 。
   yi ge li zi :
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// sheng ming yi ge xian cheng , wo men jiao ta TFrist
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Tfrist = class(TThread)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
protected
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Execute;override;// fu gai Execute zhe ge chou xiang de fang fa , zhe shi ni bi xu zuo de shi qing
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Form1: TForm1;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Ci : array[0..1000] of integer;// yi ge quan ju bian liang , wo men jiang yong TFrist lai fang wen ta
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
...
WIN32下DELPHI中的多线程【深入VCL源码】(一)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
...{ Tfrist }
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Tfrist.Execute;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
i : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
inherited;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
OnTerminate := Form1.ThreadDone;// zhu yi yi xia zhe li
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FreeOnTerminate := true;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
for i := 0 to 1000 do
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ci[i] := i;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure TForm1.Button1Click(Sender: TObject);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// chu shi hua quan ju bian liang
WIN32下DELPHI中的多线程【深入VCL源码】(一)
FillMemory(@ci,1000,0);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Tfrist.Create(false);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure TForm1.ThreadDone(sender: TObject);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
i : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
for I := 0 to 1000 do
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ListBox1.Items.Add(IntToStr(ci[i]))
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

   shang mian wo sheng lue le yi xie dai ma , dan da yi yi biao 。 wo men sheng ming le yi ge TFrist de lei , ta cong TThread ji cheng er lai , ta jiang dui yi ge quan ju bian liang de de shu zu CI jin xing chu shi hua , bing qie jiang chu shi hua de jie guo xian shi zai chuang ti de ListBox1 shang 。
   xie dao zhe li , ni hui fa xian shang shu dai ma zhong de ji ge “ yi dian ”, qi zhong yi ge wo xian zai yao shuo ming de jiu shi OnTerminate := Form1.ThreadDone; zhe yi ju , guan cha ThreadDone de yuan ma , ni hui fa xian ta qi shi jiu shi wan cheng jiang quan ju bian liang de nei rong xian shi zai chuang ti de LISTBOX zhong , zhe shi , ni ke neng hui wen , zhi jie xie zai xian cheng li , bu ke yi ma ? wei shen me yao zhe yang ? yuan yin hen jian dan 。 da duo shu V C L zai bei she ji shi , dou zhi kao lv le zai ren he shi ke zhi you yi ge xian cheng lai fang wen ta 。 qi ju xian xing you qi ti xian zai V C L de yong hu jie mian bu fen 。 tong shi , yi xie fei yong hu jie mian bu fen ye bu shi xian cheng an quan de 。
   1. fei yong hu jie mian de V C L
   shi ji shang V C L zhi you hen shao de bu fen bao zheng shi xian cheng an quan de 。 ke neng zai zhe hen shao de bu fen zhong , zui rang ren zhu yi de shi V C L de shu xing liu ji zhi 。V C L de liu ji zhi que bao le zu jian liu neng bei duo xian cheng an quan di du xie 。 qing ji zhu ji shi zui ji chu de V C L lei ( zhu ru TList), ye bu shi wei an quan di tong shi cao zuo duo ge xian cheng er she ji de 。 dui mou xie qing kuang , V C L ti gong le yi xie xian cheng an quan de ti dai , bi ru , yong TThreadList lai ti dai TList ke yi jie jue duo ge xian cheng cao zuo de wen ti 。
   2. yong hu jie mian de V C L
   V C L yao qiu suo you de yong hu jie mian kong zhi yao fa sheng zai yi ge ying yong cheng xu de zhu xian cheng de huan jing zhong ( xian cheng an quan de TCanvas lei chu wai )。 dang ran , li yong ji shu shou duan shi ke yi you xiao di li yong fu shu xian cheng geng xin yong hu jie mian de ( hou mian jiang hui tao lun )。
   dui V C L de fang wen zhi neng zai zhu xian cheng zhong 。 zhe jiang yi wei zhe : suo you xu yao yu yong hu da jiao dao de dai ma dou zhi neng zai zhu xian cheng de huan jing zhong zhi xing 。 zhe shi qi jie gou shang ming xian de bu zu , bing qie zhe zhong xu qiu kan qi lai zhi ju xian zai biao mian shang , dan ta shi ji shang you yi xie you dian 。 shou xian , zhi you yi ge xian cheng neng gou fang wen yong hu jie mian , zhe jian shao le bian cheng de fu duo xing 。Win32 yao qiu mei ge chuang jian chuang kou de xian cheng dou yao shi yong GetMessage() jian li zi ji de xiao xi xun huan 。 zheng ru ni suo xiang de , zhe yang de cheng xu jiang hui fei chang nan yu tiao shi , yin wei xiao xi de lai yuan shi zai tai duo le 。 qi ci , you yu V C L zhi yong yi ge xian cheng lai fang wen ta , na xie yong yu ba xian cheng tong bu de dai ma jiu ke yi sheng lue le , cong er gai shan le ying yong cheng xu de xing neng 。
   na me , ru guo you duo ge xian cheng yao fang wen VCL, zen me ban ne ? you zhe me ji ge fang fa :
   1、 li yong TThread de OnTerminate shu xing , ta shi yi ge TNofityEvent lei xing , ta zhi ding de guo cheng jiang zai xian cheng zhi xing wan bi zhi hou yun xing , bing qie shi yun xing zai zhu xian cheng huan jing zhong de , wo shang mian de dai ma jiu shi shi yong le zhe zhong fang fa
   2、 li yong TThread de Synchronize,
   class procedure Synchronize(ASyncRec: PSynchronizeRecord); overload;
   ta de zuo yong shi zai zhu xian cheng zhong zhi xing yi ge fang fa , wo men shang mian de li zi , ru guo bu yong OnTerminate, na me ke yi zhe me gai ,
  
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Tfrist = class(TThread)
WIN32下DELPHI中的多线程【深入VCL源码】(一)
private
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure GetResut;// wo men sheng ming le yi ge guo cheng GetResutlt; ta bu bao han ren he shen shu
WIN32下DELPHI中的多线程【深入VCL源码】(一)
protected
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Execute;override;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
//GetResut de shi xian bu fen
WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Tfrist.GetResut;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
i : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
for I := 0 to 1000 do
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Form1.ListBox1.Items.Add(IntToStr(ci[i]))
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

WIN32下DELPHI中的多线程【深入VCL源码】(一)
procedure Tfrist.Execute;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
var
WIN32下DELPHI中的多线程【深入VCL源码】(一)
i : integer;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
begin
WIN32下DELPHI中的多线程【深入VCL源码】(一)
inherited;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
OnTerminate := Form1.ThreadDone;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// FreeOnTerminate := true;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
for i := 0 to 1000 do
WIN32下DELPHI中的多线程【深入VCL源码】(一)
ci[i] := i;
WIN32下DELPHI中的多线程【深入VCL源码】(一)
// tiao yong Synchronize
WIN32下DELPHI中的多线程【深入VCL源码】(一)
Synchronize(GetResut);
WIN32下DELPHI中的多线程【深入VCL源码】(一)
end;
WIN32下DELPHI中的多线程【深入VCL源码】(一)

   3、 li yong tong xun lai wan cheng 。 li ru wo men ke yi li yong xiao xi , kan shang mian de Execute, zai ta de xun huan zhi xing wan bi zhi hou , wo men ke yi fa song yi ge zi ding yi xiao xi , ran hou chuang kou chu li zhe ge xiao xi 。
  shen kao wen xian :
  1、《delphi5 kai fa ren yuan zhi nan 》
  2、《WINDOWS gai xin bian cheng 》
  zhu : zhuan zai qing zhu ming chu chu , xie xie !
  wei wan dai xu !【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
xian cheng de ji chu zhi shi xian cheng de zu cheng 。 xian cheng you liang bu fen zu cheng 。 1、 yi ge shi xian cheng de nei gai dui xiang , cao zuo xi tong yong ta lai dui xian cheng shi shi guan li 。 nei gai dui xiang ye shi xi tong yong lai cun fang xian cheng tong ji xin xi de di fang 。 2、 ling yi ge shi xian cheng dui zhan , ta yong yu wei hu xian cheng zai zhi xing dai ma shi xu yao de suo you han shu shen shu he ju bu bian liang 。 jin cheng cong lai bu zhi xing ren he dong xi , ta zhi shi xian cheng de rong qi 。 xian cheng zong shi zai mou ge jin cheng huan jing zhong chuang jian de , er qie ta de zheng ge shou ming qi dou zai gai jin cheng zhong 。 zhe yi wei zhe xian cheng zai ta de jin cheng di zhi kong jian zhong zhi xing dai ma , bing qie zai jin cheng de di zhi kong jian zhong dui shu ju jin xing cao zuo 。 yin ci , ru guo zai dan jin cheng huan jing zhong , ni you liang ge huo duo ge xian cheng zheng zai yun xing , na me zhe liang ge xian cheng jiang gong xiang dan ge di zhi kong jian 。 zhe xie xian cheng neng gou zhi xing xiang tong de dai ma , dui xiang tong de shu ju jin xing cao zuo 。 zhe xie xian cheng huan neng gong xiang nei gai dui xiang ju bing , yin wei ju bing biao yi lai yu mei ge jin cheng er bu shi mei ge xian cheng cun zai 。 xian cheng shi yi zhong cao zuo xi tong dui xiang , ta biao shi zai jin cheng zhong dai ma de yi tiao zhi xing lu jing 。 zai mei yi ge Wi n32 de ying yong cheng xu zhong dou zhi shao you yi ge xian cheng , ta tong chang bei cheng wei zhu xian cheng huo mo ren xian cheng 。 zai ying yong cheng xu zhong ye ke yi zi you di chuang jian bie de xian cheng qu zhi xing qi ta ren wu 。 xian cheng ji shu shi bu tong de dai ma ke yi tong shi yun xing 。 dang ran , zhi you zai duo C P U de ji suan ji shang , duo ge xian cheng cai neng gou zhen zheng di tong shi yun xing 。 zai dan ge CPU shang , you yu cao zuo xi tong ba C P U de shi jian fen cheng hen duan de pian duan fen pei gei mei ge xian cheng , zhe yang gei ren de gan jiao hao xiang shi duo ge xian cheng zhen de tong shi yun xing , ta men zhi shi “ kan qi lai ” tong shi zai yun xing 。 Win32 shi yi zhong qiang zhan shi cao zuo xi tong , cao zuo xi tong fu ze guan li na ge xian cheng zai shen me shi hou zhi xing 。 ru guo dang xian cheng 1 zan ting zhi xing shi , xian cheng 2 cai you ji hui huo de C P U shi jian , wo men shuo xian cheng 1 shi qiang zhan de 。 ru guo mou ge xian cheng de dai ma xian ru si xun huan , zhe bing bu ke pa , cao zuo xi tong reng hui an pai shi jian gei qi ta xian cheng 。 chuang jian yi ge xian cheng zhu yi : mei ge xian cheng bi xu yong you yi ge jin ru dian han shu , xian cheng cong zhe ge jin ru dian kai shi yun xing 。 xian cheng han shu ke yi shi yong ren he he fa de ming zi 。 ke yi gei xian cheng han shu chuan di dan ge shen shu , shen shu de han yi you ni zi ji ding yi 。 xian cheng han shu bi xu you yi ge fan hui zhi , ta jiang cheng wei gai xian cheng de tui chu dai ma 。 xian cheng han shu ying gai jin ke neng de shi yong han shu shen shu he ju bu bian liang 。 xian cheng han shu lei si xia mian de yang zi (Object Pascal): [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]// zhu yi zui hou de stdcall, hou mian wo hui miao shu yi xie you yong de dong xi [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]function MyThread(info : Pointer):DWORD; stdcall; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to Pinfo(info)^.count-1 do [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Form1.Canvas.TextOut(Pinfo(info)^.x,Pinfo(info)^.y,inttostr(i)); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Result := 0; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; shang mian de de dai ma gong neng hen jian dan , ni ke yi zai cheng xu zhong zhi jie tiao yong , li ru zhe yang : [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]type [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Tinfo = record [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] count : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] x : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] y : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Pinfo= ^Tinfo; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]... [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.Button4Click(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi : Pinfo; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi :=AllocMem(sizeof(tinfo)); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi^.count := 1000000; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi^.x := 100; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi^.y := 400; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyThread(ppi); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; dang ni zai yi ge chuang kou zhong yong zhe yang de fang shi tiao yong shi , ni hui fa xian zai zhi xing de guo cheng zhong , ni jiang wu fa zai chuang kou shang jin xing qi ta cao zuo , yin wei ta gong zuo yu ni cheng xu de zhu xian cheng zhi zhong 。 ru guo ci shi , ni huan xi wang chuang kou ke yi jin xing qi ta cao zuo 。 zen me ban ? rang ta zai hou tai gong zuo , rang ta cheng wei ling yi ge xian cheng , shi de bu tong de dai ma ke yi tong shi yun xing 。 zuo fa hen jian dan , ru guo xiang yao chuang jian yi ge huo duo ge fu zhu xian cheng , zhi xu yao rang yi ge yi jing zai yun xing de xian cheng lai tiao yong CreateThread, yuan xing ru xia : [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]HANDLE CreateThread( [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] DWORD dwStackSize, // initial thread stack size, in bytes [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] LPVOID lpParameter, // argument for new thread [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] DWORD dwCreationFlags, // creation flags [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] LPDWORD lpThreadId // pointer to returned thread identifier [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ); dang CreateThread, bei tiao yong shi , xi tong chuang jian yi ge xian cheng nei gai dui xiang 。 gai xian cheng nei gai dui xiang bu shi xian cheng ben shen , er shi cao zuo xi tong yong lai guan li xian cheng de jiao xiao de shu ju jie gou 。 ke yi jiang xian cheng nei gai dui xiang shi wei you guan yu xian cheng de tong ji xin xi zu cheng de yi ge xiao xing shu ju jie gou 。 xi tong cong jin cheng de di zhi kong jian zhong fen pei nei cun , gong xian cheng de dui zhan shi yong 。 xin xian cheng yun xing de jin cheng huan jing yu chuang jian xian cheng de huan jing xiang tong 。 yin ci , xin xian cheng ke yi fang wen jin cheng de nei gai dui xiang de suo you ju bing 、 jin cheng zhong de suo you nei cun he zai zhe ge xiang tong de jin cheng zhong de suo you qi ta xian cheng de dui zhan 。 zhe shi de dan ge jin cheng zhong de duo ge xian cheng que shi neng gou fei chang rong yi di hu xiang tong xin 。 xia mian lai shuo zhe ge han shu de ji ge shen shu : 1、psa ci shen shu shi zhi xiang SECURITY_ATTRIBUTES jie gou de zhi zhen 。 ru guo xiang yao gai xian cheng nei gai dui xiang de mo ren an quan shu xing , ke yi ( bing qie tong chang neng gou ) chuan di NULL。 ru guo xi wang suo you de zi jin cheng neng gou ji cheng gai xian cheng dui xiang de ju bing , bi xu she ding yi ge SECURITY_ATTRIBUTES jie gou , ta de bInheritHandle( shi fou ke ji cheng ) cheng yuan bei chu shi hua wei True, guan yu SECURITY_ATTRIBUTES, yin wei ci wen de mu de bu shi jie shao ta , suo yi zhe li bu zuo xiang xi jie shao , ju ti ke yi shen kao MSDN。 tong chang shi yong , wo men chuan di null jiu gou le 。 2、cbStack yong yu she ding xian cheng ke yi jiang duo shao di zhi kong jian yong yu ta zi ji de dui zhan 。 dang tiao yong CrateThread shi , ru guo chuan di de zhi bu shi 0, jiu neng shi gai han shu jiang suo you de cun chu qi bao liu bing fen pei gei xian cheng de dui zhan 。 you yu suo you de cun chu qi yu xian zuo le fen pei , yin ci ke yi que bao xian cheng yong you zhi ding rong liang de ke yong dui zhan cun chu qi 。 tong chang zhuang kuang xia , wo men hui she zhi wei 0。 3、pfnStartAddr and pvParam,pfnStartAddr shen shu yong yu zhi ming xiang yao xin xian cheng zhi xing de xian cheng han shu de di zhi 。 xian cheng han shu de pvParam shen shu yu yuan xian chuan di gei CreateThread de pvParam shen shu shi xiang tong de 。CreateThread shi yong gai shen shu bu zuo bie de shi qing , zhi shi zai xian cheng qi dong zhi xing shi jiang gai shen shu chuan di gei xian cheng han shu 。 gai shen shu ti gong le yi ge jiang chu shi hua zhi chuan di gei xian cheng han shu de shou duan 。 gai chu shi hua shu ju ji ke yi shi shu zi zhi , ye ke yi shi zhi xiang bao han qi ta xin xi de yi ge shu ju jie gou de zhi zhen 。 ci shi hui tou zai qu kan wo shang mian li zi shang de MyThread, ni hui fa xian ta you yi ge wu lei xing de zhi zhen shen shu ( yong C lai miao shu , ying gai shi PVOID), zai chuang jian xian cheng shi , zhe ge shen shu jiu tong guo pvParam lai fu zhi 。 4、fdwcreate ci shen shu ke yi she ding yong yu kong zhi chuang jian xian cheng de qi ta biao zhi 。 ta ke yi shi liang ge zhi zhong de yi ge 。 ru guo gai zhi shi 0, na me xian cheng chuang jian hou ke yi li ji jin xing tiao du 。 ru guo gai zhi shi CREATE_ SUSPENDED, xi tong ke yi wan zheng di chuang jian xian cheng bing dui ta jin xing chu shi hua , dan shi yao zan ting gai xian cheng de yun xing , zhe yang ta jiu wu fa jin xing tiao du 。 zai DELPHI de WINDOWS.PAS dan yuan , ni ke yi fa xian ta de ding yi CREATE_SUSPENDED= $00000004; 5、pdwThreadId zui hou yi ge shen shu bi xu shi Dword de yi ge you xiao di zhi ,CreateThread shi yong zhe ge di zhi lai cun fang xi tong fen pei gei xin xian cheng de ID. you le shang mian zhe xie ji chu , xia mian wo men jiu shi yong createThread lai chuang jian gang cai na ge MyThread xian cheng (DELPHI7); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]... [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]// yi ge zi ding yi lei xing [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]type [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Tinfo = record [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] count : integer;// ji shu qi ge shu [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] x : integer;// yao xian shi zai chuang ti shang wei zhi de heng zuo biao [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] y : integer;// zong zuo biao [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Pinfo=^Tinfo; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyThreadHad : THandle;// yi ge quan ju bian liang , yong lai jie shou CreateThread chuang jian xin xian cheng de ju bing [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]... [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.Button4Click(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi : Pinfo; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyThreadId : DWORD; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url] ...{ fen pei kong jian , zhu yi , yin wei zhe li wo zhi shi yi ge yong lai yan shi CreateThread shi yong de dai ma , suo yi mei you shi fang pp, dan you xiu de dai ma zui hou ji de fen pei le kong jian yi ding yao shi fang } [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi :=AllocMem(sizeof(tinfo)); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // chu shi hua [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi^.count := 100000; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi^.x := 100; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ppi^.y := 400; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // xia mian zhe xing dai ma shi guan jian [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] MyThreadHad := CreateThread(nil,0,@MyThread,ppi,0,MyThreadId); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] zhi xing ci duan dai ma , ni hui fa xian , ta yi ran hui zai ping mu zhi ding qu yu shu chu wen zi , he zui kai shi shi wo men yong ba MyThread zai zhu xian cheng zhong yun xing bu tong de shi , ci shi , ni yi ran ke yi dui chuang kou jin xing qi ta cao zuo 。 kan dai ma de zui hou yi xing , ta shi yong le createThread, kan ta de shen shu , di yi ge nil yi ji di er ge 0 yi wai zhe , ta shi yong mo ren de an quan she zhi yi ji mo ren de xian cheng dui zhan da xiao , di san ge shen shu shi MyThread de di zhi ( zhu yi @ fu hao ), ran hou wo men chuan di le ppi zhe ge Pinfo lei xing de zhi zhen , shi de xian cheng han shu jie shou yi ge shen shu , ru guo ni bu zhun bei rang xian cheng jie shou zhe ge shen shu , yong nil,fdwcreate shen shu , wo men fu zhi wei 0, yi wei zhe wo men xi wang xian cheng li ji zhi xing , zui hou yi ge shen shu yong lai jie shou xin xian cheng de ID。 rang wo men lai kan kan CreateThread dou gan le xie shen me 。 [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://p.blog.csdn.net/images/p_blog_csdn_net/wudi_1982/ xian cheng chuang jian he chu shi hua shi yi tu .JPG[/img][/url] shang tu xian shi le xi tong zai chuang jian xian cheng he dui xian cheng jin xing chu shi hua shi bi xu zuo xie shen me gong zuo 。 tiao yong CreateThread ke shi xi tong chuang jian yi ge xian cheng nei gai dui xiang 。 gai dui xiang de chu shi shi yong ji shu shi 2( zai xian cheng ting zhi yun xing he cong CreateThread fan hui de ju bing guan bi zhi qian , xian cheng nei gai dui xiang bu hui bei che xiao )。 xian cheng de nei gai dui xiang de qi ta shu xing ye bei chu shi hua , zan ting ji shu bei she zhi wei 1, tui chu dai ma shi zhong wei STILL_ACTIVE(0 x 1 0 3), gai dui xiang she zhi wei wei tong zhi zhuang tai 。 yi dan nei gai dui xiang chuang jian wan cheng , xi tong jiu fen pei yong yu xian cheng de dui zhan de nei cun 。 gai nei cun shi cong jin cheng de di zhi kong jian fen pei er lai de , yin wei xian cheng bing bu yong you ta zi ji de di zhi kong jian 。 ran hou xi tong jiang liang ge zhi xie ru xin xian cheng de dui zhan de shang duan ( xian cheng dui zhan zong shi cong nei cun de gao di zhi xiang di di zhi jian li )。 xie ru dui zhan de di yi ge zhi shi chuan di gei CreateThread de pvParam shen shu de zhi 。 jin kao ta de xia mian shi chuan di gei CreateThread de pfnStartAddr shen shu de zhi 。 mei ge xian cheng dou you ta zi ji de yi zu C P U ji cun qi , cheng wei xian cheng de shang xia wen 。 gai shang xia wen fan yang le xian cheng shang ci yun xing shi gai xian cheng de CPU ji cun qi de zhuang tai 。 xian cheng de zhe zu C P U ji cun qi bao cun zai yi ge CONTEXT jie gou 。CONTEXT jie gou ben shen ze bao han zai xian cheng de nei gai dui xiang zhong 。 zhi ling zhi zhen he dui zhan zhi zhen ji cun qi shi xian cheng shang xia wen zhong liang ge zui chong yao de ji cun qi 。 xian cheng zong shi zai jin cheng de shang xia wen zhong yun xing de 。 yin ci , zhe xie di zhi dou yong yu biao shi yong you xian cheng de jin cheng di zhi kong jian zhong de nei cun 。 dang xian cheng de nei gai dui xiang bei chu shi hua shi ,CONTEXT jie gou de dui zhan zhi zhen ji cun qi bei she zhi wei xian cheng dui zhan shang yong lai fang zhi pfnStartAddr de di zhi 。 dang xian cheng wan quan chu shi hua hou , xi tong jiu yao cha kan CREATE_SUSPENDED biao zhi shi fou yi jing chuan di gei CreateThread。 ru guo gai biao zhi mei you chuan di , xi tong bian jiang xian cheng de zan ting ji shu di jian wei 0, gai xian cheng ke yi tiao du dao yi ge jin cheng zhong 。 ran hou xi tong yong shang ci bao cun zai xian cheng shang xia wen zhong de zhi jia zai dao shi ji de C P U ji cun qi zhong 。 zhe shi xian cheng jiu ke yi zhi xing dai ma , bing dui ta de jin cheng de di zhi kong jian zhong de shu ju jin xing cao zuo 。 zai zhe li , wo huan yao jian dan de miao shu yi xia CONTEXT jie gou , yin wei WIN32 shi qiang zhan shi cao zuo xi tong , yi ge xian cheng ji hu bu ke neng yong yuan de zhan ju CPU, ye jiu shi shuo , ta hui zai yi ding shi jian hou ( zai WINDOWS zhong , da gai shi 20ms de shi jian ), bei CPU fang zai yi bian , yi duan shi jian zhi hou , cai ke yi chong xin huo de CPU shi jian pian , ci shi jiu you yi ge wen ti , xian cheng xian zai zhi xing dao le na li ,CPU zai zai ci fen pei gei ta shi jian pian zhi xing de shi hou , bi xu zhi dao zhe xie xin xi , nan dao yao cong 0 kai shi ma ?CONTEXT jie gou de zuo yong jiu shi yong lai jie jue zhe ge wen ti 。 zai Platform SDK zhong , ni ke yi kan dao xia mian de xin xi : “CONTEXT jie gou bao han le te ding chu li qi de ji cun qi shu ju 。 xi tong shi yong CONTEXT jie gou zhi xing ge zhong nei bu cao zuo 。 mu qian , yi jing cun zai wei Intel、MIPS、Alpha he PowerPC chu li qi ding yi de CONTEXT jie gou 。 ruo yao le jie zhe xie jie gou de ding yi , shen jian tou wen jian WinNT.h”。 gai wen dang bing mei you shuo ming gai jie gou de cheng yuan , ye mei you miao shu zhe xie cheng yuan shi shui , yin wei zhe xie cheng yuan yao qu jue yu Windows zai na ge CPU shang yun xing 。 shi ji shang , zai Windows ding yi de suo you shu ju jie gou zhong ,CONTEXT jie gou shi te ding yu CPU de wei yi shu ju jie gou 。 na me CONTEXT jie gou zhong jiu jing cun zai na xie dong xi ne ? ta bao han le zhu ji C P U shang de mei ge ji cun qi de shu ju jie gou 。 zai x86 ji suan ji shang , shu ju cheng yuan shi Eax、Ebx、Ecx、Edx deng deng 。 ru guo shi Alpha chu li qi , na me shu ju cheng yuan bao kuo IntV0、IntT0、IntT1、IntS0、In tRa he IntZero deng deng 。 Windows shi ji shang yuan xu cha kan xian cheng nei gai dui xiang de nei bu qing kuang , yi bian zhua qu ta dang qian de yi zu CPU ji cun qi 。 ruo yao jin xing zhe xiang cao zuo , zhi xu yao tiao yong GetThreadContext han shu 。 guan yu ci han shu de shi yong , wo men xia ci zai shuo 。 xian cheng de zhong zhi zhong zhi yi ge xian cheng de yun xing , you 4 ge fang fa : 1、 xian cheng han shu fan hui , zhe shi zui hao de 2、 tiao yong ExitThread han shu , xian cheng jiang zi dong che xiao 3、 tiao yong TerminateThread han shu 4、 bao han xian cheng de jin cheng zhong zhi yun xing xian cheng han shu fan hui shi zhong dou ying gai jiang xian cheng she ji cheng zhe yang de xing shi , ji dang xiang yao xian cheng zhong zhi yun xing shi , ta men jiu neng gou fan hui 。 zhe shi que bao suo you xian cheng zi yuan bei zheng que di qing chu de wei yi ban fa 。 ru guo xian cheng neng gou fan hui , jiu ke yi que bao xia lie shi xiang de shi xian : • zai xian cheng han shu zhong chuang jian de suo you C + + dui xiang yun jiang tong guo ta men de che xiao han shu zheng que di che xiao 。 • cao zuo xi tong jiang zheng que di shi fang xian cheng dui zhan shi yong de nei cun 。 • xi tong jiang xian cheng de tui chu dai ma ( zai xian cheng de nei gai dui xiang zhong wei hu ) she zhi wei xian cheng han shu de fan hui zhi 。 • xi tong jiang di jian xian cheng nei gai dui xiang de shi yong ji shu 。 tiao yong Exitthread han shu void ExitThread(DWORD dwExitCode); gai han shu jiang zhong zhi xian cheng de yun xing , bing dao zhi cao zuo xi tong qing chu gai xian cheng shi yong de suo you cao zuo xi tong zi yuan 。 dan shi cheng xu zhong yong dao de zi yuan ( li ru DELPHI lei dui xiang ) jiang bu bei che xiao 。 tiao yong TerminateThread han shu Bool TerminateThread(HANDLE hThread,DWORD dwExitCode); guan chan zhe ge han shu he ExitThread de qu bie , ni hui fa xian ta chu le you dwExitCode zhe ge tui chu ma shen shu zhi wai , huan bao han le ke zhi ding xian cheng de ju bing shen shu 。 kan dao zhe li ni jiu ying gai hui xiang dao liang zhe de qu bie ,Exitthread zong shi che xiao tiao yong de xian cheng , er TerminateThread neng gou che xiao ren he xian cheng 。hThread shen shu yong yu biao shi bei zhong zhi yun xing de xian cheng de ju bing 。 dang xian cheng zhong zhi yun xing shi , ta de tui chu dai ma cheng wei ni zuo wei dwExitCode shen shu chuan di de zhi 。 tong shi , xian cheng de nei gai dui xiang de shi yong ji shu ye bei di jian 。 zhi de zhu yi de shi , ci han shu shi yi bu yun xing de han shu , ye jiu shi shuo , ta gao su xi tong ni xiang yao xian cheng zhong zhi yun xing , dan shi , dang han shu fan hui shi , bu neng bao zheng xian cheng bei che xiao 。 ru guo xu yao que qie di zhi dao gai xian cheng yi jing zhong zhi yun xing , bi xu tiao yong WaitForSingleObject huo zhe lei si de han shu , chuan di xian cheng de ju bing 。 zai jin cheng zhong zhi shi che xiao xian cheng zhe shi hen rong yi xiang dao de 。 wu xu guo duo jie shi 。 xian cheng zhong zhi shi fa sheng de cao zuo dang xian cheng zhong zhi yun xing shi , hui fa sheng xia lie cao zuo : • xian cheng yong you de suo you yong hu dui xiang yun bei shi fang 。 zai Windows zhong , da duo shu dui xiang shi you bao han chuang jian zhe xie dui xiang de xian cheng de jin cheng yong you de 。 dan shi yi ge xian cheng yong you liang ge yong hu dui xiang , ji chuang kou he gua gou 。 dang xian cheng zhong zhi yun xing shi , xi tong hui zi dong che xiao ren he chuang kou , bing qie xie zai xian cheng chuang jian de huo an zhuang de ren he gua gou 。 qi ta dui xiang zhi you zai yong you xian cheng de jin cheng zhong zhi yun xing shi cai bei che xiao 。 • xian cheng de tui chu dai ma cong STILL_ACTIVE gai wei chuan di gei ExitThread huo TerminateThread de dai ma • xian cheng nei gai dui xiang de zhuang tai bian wei yi tong zhi 。 • ru guo xian cheng shi jin cheng zhong zui hou yi ge huo dong xian cheng , xi tong ye jiang jin cheng shi wei yi jing zhong zhi yun xing 。 • xian cheng nei gai dui xiang de shi yong ji shu di jian 1。 dang yi ge xian cheng zhong zhi yun xing shi , zai yu ta xiang guan lian de xian cheng nei gai dui xiang de suo you wei jie shu de yin yong guan bi zhi qian , gai nei gai dui xiang bu hui zi dong bei shi fang 。 yi dan xian cheng bu zai yun xing , xi tong zhong jiu mei you bie de xian cheng neng gou chu li gai xian cheng de ju bing 。 ran er bie de xian cheng ke yi tiao yong GetExitcodeThread lai jian cha you hThread biao shi de xian cheng shi fou yi jing zhong zhi yun xing 。 ru guo ta yi jing zhong zhi yun xing , ze que ding ta de tui chu dai ma . BOOL GetExitcodeThread(HANDLE hThread,PDWORD pdwExitcode); tui chu dai ma de zhi zai pdwExitcode); zhi xiang de DWORD zhong fan hui 。 ru guo tiao yong GetExitcodeThread shi xian cheng shang wei zhong zhi yun xing , gai han shu jiu yong STILL_ACTIVE biao shi fu ( ding yi wei 0x103) tian ru DWORD。 ru guo gai han shu yun xing cheng gong , bian fan hui T R U E。 shang mian miao shu le jie shu xian cheng de duo zhong ban fa , zhe li bi xu shuo ming yi dian , ru guo you ke neng , na jin liang shi yong di yi zhong fang shi lai jie shu xian cheng , ta ke yi que bao ni shi fang le suo you de zi yuan 。 hao de cheng xu ying gai jin ke neng de jian shao dui ke hu zi yuan de lang fei 。 stdcall zhun que de shuo ,stdcall zhe ge biao shi fu ben lai he xian cheng mei you zhi jie de lian xi , dan yin wei wo zhe li de shi li dai ma shi yong Object Pascal xie de , er wo men tiao yong de CreateThread ze shi yong c shi xian de , zhe liang zhong yu yan de han shu ru zhan de fang shi shi bu tong de ,pascal shi cong zuo dao you 。 jia shang stdcall, ke yi shi de ru zhan fang shi gai wei cong you dao zuo yi fu he bie de yu yan de xi guan 。 wo men shang mian tiao yong createThread han shu shi , yin wei wo chuan di le na ge wu lei xing de zhi zhen shen shu , suo yi , bi xu jia shang stdcall zhi ming ru zhan fang shi , fou ze hui chu xian di zhi fang wen cuo wu 。 dang ran , ru guo ni bing bu jue ding chuan di shen shu , ni ye ke yi bu shi yong stdcall。 bu guo zuo wei yi zhong hao de bian ma xi guan , ni zui hao huan shi jia shang 。 DELPHI zhong chuang jian xian cheng ru guo ni zhi xiang zuo yi ge dai ma ban yun gong , ni wan quan ke yi bu le jie shang mian de nei rong , dan ru guo ni xiang cheng wei yi ge he ge de WIN32 cheng xu yuan , shen ru zhe xie nei rong , bi ni fu qian de duo xue yi men yu yan you yong 。 DELPHI ba you guan xian cheng de API feng zhuang zai TThread zhe ge Object Pascal de dui xiang zhong 。 jie he shang mian de nei rong , xian qu kan TThread yuan ma [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] TThread = class [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] private [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF MSWINDOWS} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FHandle: THandle; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FThreadID: THandle; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF LINUX} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // ** FThreadID is not THandle in Linux ** [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FThreadID: Cardinal; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FCreateSuspendedSem: TSemaphore; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FInitialSuspendDone: Boolean; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FCreateSuspended: Boolean; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FTerminated: Boolean; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FSuspended: Boolean; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FFreeOnTerminate: Boolean; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FFinished: Boolean; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FReturnValue: Integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FOnTerminate: TNotifyEvent; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FSynchronize: TSynchronizeRecord; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FFatalException: TObject; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure CallOnTerminate; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] class procedure Synchronize(ASyncRec: PSynchronizeRecord); overload; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF MSWINDOWS} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] function GetPriority: TThreadPriority; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure SetPriority(Value: TThreadPriority); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF LINUX} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // ** Priority is an Integer value in Linux [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] function GetPriority: Integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure SetPriority(Value: Integer); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] function GetPolicy: Integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure SetPolicy(Value: Integer); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure SetSuspended(Value: Boolean); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] protected [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure CheckThreadError(ErrCode: Integer); overload; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure CheckThreadError(Success: Boolean); overload; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure DoTerminate; virtual; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Execute; virtual; abstract; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Synchronize(Method: TThreadMethod); overload; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property ReturnValue: Integer read FReturnValue write FReturnValue; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property Terminated: Boolean read FTerminated; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] public [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] constructor Create(CreateSuspended: Boolean); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] destructor Destroy; override; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure AfterConstruction; override; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Resume; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Suspend; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Terminate; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] function WaitFor: LongWord; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] class procedure Synchronize(AThread: TThread; AMethod: TThreadMethod); overload; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] class procedure StaticSynchronize(AThread: TThread; AMethod: TThreadMethod); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property FatalException: TObject read FFatalException; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property FreeOnTerminate: Boolean read FFreeOnTerminate write FFreeOnTerminate; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF MSWINDOWS} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property Handle: THandle read FHandle; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property Priority: TThreadPriority read GetPriority write SetPriority; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF LINUX} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // ** Priority is an Integer ** [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property Priority: Integer read GetPriority write SetPriority; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property Policy: Integer read GetPolicy write SetPolicy; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property Suspended: Boolean read FSuspended write SetSuspended; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF MSWINDOWS} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property ThreadID: THandle read FThreadID; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$IFDEF LINUX} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // ** ThreadId is Cardinal ** [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property ThreadID: Cardinal read FThreadID; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{$ENDIF} [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; cong TThread de sheng ming zhong ke yi kan chu , ta ding yi le Windows he Linux xia fen bie yao wan cheng de cao zuo , zhe li wo men zhi tan WIN32,TThread zhi jie cong TObject ji cheng , yin wei , ta bu shi zu jian 。 ni huan ke yi kan dao ta you yi ge Execute de fang fa procedure Execute; virtual; abstract; bing qie ni ke yi kan dao , ta shi chou xiang de , yin wei , bu neng chuang jian TThread de shi li , ni zhi neng chuang jian ta de pai sheng lei de shi li 。 zai qu kan kan ta de gou zao han shu , ni hui kan dao zhe yang yi ju dai ma FHandle := BeginThread(nil, 0, @ThreadProc, Pointer(Self), CREATE_SUSPENDED, FThreadID); zai shen ru qu kan zhe ge BeginThread, Result := CreateThread(SecurityAttributes, StackSize, @ThreadWrapper, P,CreationFlags, ThreadID); ni kan dao le shen me ? shi de ,CreateThread, jie he zhe liang ju , kan kan ta dou gan le xie shen me , mo ren de an quan shu xing , mo ren de dui zhan da xiao , yi ge ru kou di zhi , yi ge shen shu , yi ge chuang jian biao zhi , huan you yi ge threadid。 ni he ben wen zui kai shi de na xie nei rong dui shang le ma ? wo men you kan dao ta chuan di de xian cheng han shu shi ThreadProc, zai qu kan kan ta 。 xia mian zhi tie le yi xie he ben wen you guan xi de dai ma [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] try [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] if not Thread.Terminated then [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] try [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Thread.Execute; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] except [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Thread.FFatalException := AcquireExceptionObject; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] finally ta shou xian gen ju TThread lei zhong de yi ge shu xing Terminated( bu er lei xing ) lai pan duan xian cheng de zhuang tai , ru guo ni mei you tong guo wai bu dai ma jiang Terminated shen zhi wei true, ta jiang hui zhi xing Execute( zhu yi zhe ge fang fa , wo men gang cai ti dao guo ta shi yi ge chou xiang de , ni bi xu rang ta gan dian shen me , ye jiu shi shuo ,Tthread.execute jiang shi ni de xian cheng jiang yao zhi xing de cao zuo )。 ran hou shi yi chang de chu li 。 ni shi fou dui DELPHI de TThread you dian le jie le ne ? ru guo you xing qu , hao hao kan kan ta de yuan ma ba 。 shuo dao zhe li ,DELPHI zhong TThread chuang jian yi ge xian cheng de ji ben liu cheng jiu chu lai le 。 tiao yong zi ji de gou zao han shu , chuan di yi ge bu er lei xing de bian liang , zhe ge bian liang dui ying CreateThread han shu de fdwcreate shen shu , yong lai jue ding xian cheng shi li ji zhi xing huan shi gua qi , gou zao han shu you tiao yong le yi ge BeginThread, er zheng shi zhe ge BeginThread tiao yong le WIN API CreateThread, ta jiang yi ge ThreadProc xian cheng han shu chuan di gei CreateThread, er zhe ge ThreadProc ze tiao yong ni bi xu fu gai de fang fa Execute lai wan cheng ni xiang yao jin xing de cao zuo 。 zai lai kan kan ta de zhong zhi , ji xu gang cai de nei rong , kan ThreadProc zhe ge han shu de xia mian dai ma , ni hui fa xian , dang Execute zhi xing wan bi zhi hou , ta jiu ren wei zhe ge xian cheng zhong zhi le , ta tiao yong le EndThread(Result), ran hou zhe ge EndThread you tiao yong le ExitThread(ExitCode)。 dang jie shu shi yong TThread dui xiang shi , ying gai que bao yi jing ba zhe ge Object Pascal dui xiang cong nei cun zhong qing chu le 。 zhe cai neng que bao suo you nei cun zhan you dou shi fang diao 。 jin guan zai jin cheng zhong zhi shi hui zi dong qing chu suo you de xian cheng dui xiang , dan ji shi qing chu yi bu zai yong de dui xiang , ke yi shi nei cun de shi yong xiao lv ti gao 。 huan shi ThreadProc de yuan ma , ni hui fa xian dang xian cheng de Execute zhi xing wan zhi hou , ta yao gen Thread.FFreeOnTerminate lai jue ding shi fou shi fang zi yuan 。FreeThread := Thread.FFreeOnTerminate;...if FreeThread then Thread.Free; zhe shi fei chang hao de , ye jiu shi shuo , ni ke yi tong guo zai dui FreeOnTerminate zhe ge shu xing fu zhi wei true( guan cha ta de yuan ma ,FreeOnTerminate shi FFreeOnTerminate zhe ge si you bian liang de fang wen qi ), lai rang TThread dui xiang zi dong zai xian cheng zhi xing wan bi zhi hou zi dong shi fang zi yuan 。 kan le zhe me duo , wo men ke yi shu li yi xia si lu le , shi yong TThread dui xiang , wo men bi xu cong ta pai sheng yi ge lei , ran hou ni bi xu fu gai Execute zhe ge fang fa , zai zhe li , wan cheng ni yao rang xian cheng zuo de shi qing 。 ru guo you ke neng ( huo zhe shuo jin liang , chu fei ni dui zhe ge xian cheng huan you bie de xu qiu ), huan ke yi zai zhe li tong guo she zhi FreeOnTerminate := true, shi de xian cheng zai zhi xing wan bi zhi hou zi dong shi fang zi yuan 。 wo men ke yi tong guo TThread dui xiang gou zao han shu de shen shu lai jue ding xian cheng shi fou li ji yun xing 。 yi ge li zi : [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ... [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // sheng ming yi ge xian cheng , wo men jiao ta TFrist [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Tfrist = class(TThread) [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] protected [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Execute;override;// fu gai Execute zhe ge chou xiang de fang fa , zhe shi ni bi xu zuo de shi qing [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Form1: TForm1; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Ci : array[0..1000] of integer;// yi ge quan ju bian liang , wo men jiang yong TFrist lai fang wen ta [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]... [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif[/img][/url][url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif[/img][/url]...{ Tfrist } [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure Tfrist.Execute; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] inherited; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OnTerminate := Form1.ThreadDone;// zhu yi yi xia zhe li [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FreeOnTerminate := true; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to 1000 do [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ci[i] := i; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.Button1Click(Sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // chu shi hua quan ju bian liang [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] FillMemory(@ci,1000,0); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Tfrist.Create(false); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure TForm1.ThreadDone(sender: TObject); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for I := 0 to 1000 do [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ListBox1.Items.Add(IntToStr(ci[i])) [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] shang mian wo sheng lue le yi xie dai ma , dan da yi yi biao 。 wo men sheng ming le yi ge TFrist de lei , ta cong TThread ji cheng er lai , ta jiang dui yi ge quan ju bian liang de de shu zu CI jin xing chu shi hua , bing qie jiang chu shi hua de jie guo xian shi zai chuang ti de ListBox1 shang 。 xie dao zhe li , ni hui fa xian shang shu dai ma zhong de ji ge “ yi dian ”, qi zhong yi ge wo xian zai yao shuo ming de jiu shi OnTerminate := Form1.ThreadDone; zhe yi ju , guan cha ThreadDone de yuan ma , ni hui fa xian ta qi shi jiu shi wan cheng jiang quan ju bian liang de nei rong xian shi zai chuang ti de LISTBOX zhong , zhe shi , ni ke neng hui wen , zhi jie xie zai xian cheng li , bu ke yi ma ? wei shen me yao zhe yang ? yuan yin hen jian dan 。 da duo shu V C L zai bei she ji shi , dou zhi kao lv le zai ren he shi ke zhi you yi ge xian cheng lai fang wen ta 。 qi ju xian xing you qi ti xian zai V C L de yong hu jie mian bu fen 。 tong shi , yi xie fei yong hu jie mian bu fen ye bu shi xian cheng an quan de 。 1. fei yong hu jie mian de V C L shi ji shang V C L zhi you hen shao de bu fen bao zheng shi xian cheng an quan de 。 ke neng zai zhe hen shao de bu fen zhong , zui rang ren zhu yi de shi V C L de shu xing liu ji zhi 。V C L de liu ji zhi que bao le zu jian liu neng bei duo xian cheng an quan di du xie 。 qing ji zhu ji shi zui ji chu de V C L lei ( zhu ru TList), ye bu shi wei an quan di tong shi cao zuo duo ge xian cheng er she ji de 。 dui mou xie qing kuang , V C L ti gong le yi xie xian cheng an quan de ti dai , bi ru , yong TThreadList lai ti dai TList ke yi jie jue duo ge xian cheng cao zuo de wen ti 。 2. yong hu jie mian de V C L V C L yao qiu suo you de yong hu jie mian kong zhi yao fa sheng zai yi ge ying yong cheng xu de zhu xian cheng de huan jing zhong ( xian cheng an quan de TCanvas lei chu wai )。 dang ran , li yong ji shu shou duan shi ke yi you xiao di li yong fu shu xian cheng geng xin yong hu jie mian de ( hou mian jiang hui tao lun )。 dui V C L de fang wen zhi neng zai zhu xian cheng zhong 。 zhe jiang yi wei zhe : suo you xu yao yu yong hu da jiao dao de dai ma dou zhi neng zai zhu xian cheng de huan jing zhong zhi xing 。 zhe shi qi jie gou shang ming xian de bu zu , bing qie zhe zhong xu qiu kan qi lai zhi ju xian zai biao mian shang , dan ta shi ji shang you yi xie you dian 。 shou xian , zhi you yi ge xian cheng neng gou fang wen yong hu jie mian , zhe jian shao le bian cheng de fu duo xing 。Win32 yao qiu mei ge chuang jian chuang kou de xian cheng dou yao shi yong GetMessage() jian li zi ji de xiao xi xun huan 。 zheng ru ni suo xiang de , zhe yang de cheng xu jiang hui fei chang nan yu tiao shi , yin wei xiao xi de lai yuan shi zai tai duo le 。 qi ci , you yu V C L zhi yong yi ge xian cheng lai fang wen ta , na xie yong yu ba xian cheng tong bu de dai ma jiu ke yi sheng lue le , cong er gai shan le ying yong cheng xu de xing neng 。 na me , ru guo you duo ge xian cheng yao fang wen VCL, zen me ban ne ? you zhe me ji ge fang fa : 1、 li yong TThread de OnTerminate shu xing , ta shi yi ge TNofityEvent lei xing , ta zhi ding de guo cheng jiang zai xian cheng zhi xing wan bi zhi hou yun xing , bing qie shi yun xing zai zhu xian cheng huan jing zhong de , wo shang mian de dai ma jiu shi shi yong le zhe zhong fang fa 2、 li yong TThread de Synchronize, class procedure Synchronize(ASyncRec: PSynchronizeRecord); overload; ta de zuo yong shi zai zhu xian cheng zhong zhi xing yi ge fang fa , wo men shang mian de li zi , ru guo bu yong OnTerminate, na me ke yi zhe me gai , [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]Tfrist = class(TThread) [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] private [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure GetResut;// wo men sheng ming le yi ge guo cheng GetResutlt; ta bu bao han ren he shen shu [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] protected [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] procedure Execute;override; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]//GetResut de shi xian bu fen [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure Tfrist.GetResut; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for I := 0 to 1000 do [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Form1.ListBox1.Items.Add(IntToStr(ci[i])) [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]procedure Tfrist.Execute; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]var [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] i : integer; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]begin [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] inherited; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] OnTerminate := Form1.ThreadDone; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // FreeOnTerminate := true; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] for i := 0 to 1000 do [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] ci[i] := i; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] // tiao yong Synchronize [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] Synchronize(GetResut); [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url]end; [url=http://www.wangchao.net.cn/bbs/pydetail_566834.html][img]http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif[/img][/url] 3、 li yong tong xun lai wan cheng 。 li ru wo men ke yi li yong xiao xi , kan shang mian de Execute, zai ta de xun huan zhi xing wan bi zhi hou , wo men ke yi fa song yi ge zi ding yi xiao xi , ran hou chuang kou chu li zhe ge xiao xi 。 shen kao wen xian : 1、《delphi5 kai fa ren yuan zhi nan 》 2、《WINDOWS gai xin bian cheng 》 zhu : zhuan zai qing zhu ming chu chu , xie xie ! wei wan dai xu !
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
桌球宝贝_性感在蔓延(3)
桌球宝贝_性感在蔓延(2)
银杏树下清纯女孩(9)
银杏树下清纯女孩(8)
痞子的甘南日记
疑是银河落九天
雪域坝上四——纯美色
冬日恋歌——西城杨柳弄轻柔
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有