|
|
导航: |
论坛 -> DELPHI技术
斑竹:liumazi,sephil |
|
作者: |
cc_cn (cc_cn) |
★☆☆☆☆ |
-
|
盒子活跃会员 |
|
2004/3/8 10:56:27 |
标题: |
|
加入我的收藏 |
楼主: |
如果可以该怎么用呢 下面是非常简单的代码,请看一下,错在哪儿,谢谢!!
//窗体部分 unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Unit2, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } mythread:thread_timer1; //procedure thread_count; public { Public declarations } //procedure thread_count; end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure thread_count; var i:integer; begin for i:=0 to 20000 do begin form1.Edit1.Text:=inttostr(i); end; end;
procedure TForm1.FormCreate(Sender: TObject); begin mythread:=thread_timer1.Create(true); end;
procedure TForm1.Button1Click(Sender: TObject); begin mythread.Resume; end;
end. ///线程部分 unit Unit2;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type thread_timer1 = class(TThread) private { Private declarations } protected procedure Execute; override; end;
implementation uses unit1; { thread_timer1 }
procedure thread_timer1.Execute; begin unit1.thread_count;///这句肯定是不对的,只是用来表达我的意思 end;
end.
----------------------------------------------
- |
作者: |
|
2004/3/8 11:42:34 |
1楼: |
当然可以调用,但不是你这样的用法. 首先一个thread在建立的时候,你最好把所有相关的参数都传进去.在你的例子中,你应该把form1的实例传进去,因此,你要修改你的线程的建立过程. 第二,在线程中调用过程,你最好间接的调用,也就是先建立一个线程内部的过程,无参数的.然后在这个过程中在调用你的form1的那个过程.使用同步关键字. Synchronize(.....);你自己看帮助吧.
----------------------------------------------
delphi的忠实拥戴者 一起交流DELPHI MSN: tech@delphisoft.com.cn
|
|