为什么创建这个线程会出错?(50分)

  • 主题发起人 主题发起人 边尘浪子
  • 开始时间 开始时间

边尘浪子

Unregistered / Unconfirmed
GUEST, unregistred user!
<br>一个是直接调用 MyTest &nbsp; 一个是创建了线程来调用MyTest<br>前面的 直接调用就对的, &nbsp;后面的这个就会出错<br><br>怎么回事? &nbsp;高手办我看看,说明理由<br><br>/////////////////代码如下///////////////<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; Lp = ^L;<br>&nbsp; L = packed record<br>&nbsp; &nbsp; i:integer;<br>&nbsp; end;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>var<br>&nbsp; llpp:LP;<br>&nbsp; ll:L;<br><br>implementation<br><br>{$R *.dfm}<br>function MyTest(llpp_:LP):boolean;<br>var<br>&nbsp; ll_:L;<br>begin<br>&nbsp; ll_:=llpp_^;<br>&nbsp; ShowMessage(IntToStr(ll.i));<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; d:dword;<br>begin<br>&nbsp; ll.i:=100;<br>&nbsp; llpp:=@ll;<br>// &nbsp;MyTest(llpp);<br>&nbsp; CreateThread(nil,0,@MyTest,llpp,0,d);<br>end;<br><br>end.
 
没人回答了么?<br><br>??????????????????????????????????????
 
唉,还是我给你个例子吧!为什么不行,自己一看便知!<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>procedure printh(p:pointer);stdcall;<br>procedure printc(p:pointer);stdcall;<br>&nbsp; type<br>&nbsp; MyStru = record<br>&nbsp; &nbsp; &nbsp;i:integer;<br>&nbsp; end;<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; test:mystru;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure printh(p:pointer);<br>begin<br>&nbsp; form1.caption:=inttostr((MyStru(p^).i));<br>&nbsp; ExitThread(0);<br>end;<br><br>procedure printc(p:pointer);<br>begin<br>&nbsp; TForm1(p).caption:='Hello from thread';<br>&nbsp; ExitThread(0);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>h1:cardinal;<br>begin<br>test.i:=111;<br>createthread(nil,128,@printh,@test,0,h1);<br>createthread(nil,128,@printc,self,0,h1);<br>end;<br><br>end.<br><br>
 
接受答案了.
 

Similar threads

I
回复
0
查看
646
import
I
I
回复
0
查看
798
import
I
I
回复
0
查看
705
import
I
I
回复
0
查看
783
import
I
I
回复
0
查看
758
import
I
后退
顶部