DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: fdsafdsa1234
今日帖子: 9
在线用户: 8
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 cc_cn (cc_cn) ★☆☆☆☆ -
盒子活跃会员
2004/3/8 10:56:27
标题:
在线程中可以调用过程吗 浏览:1274
加入我的收藏
楼主: 如果可以该怎么用呢
下面是非常简单的代码,请看一下,错在哪儿,谢谢!!

//窗体部分
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.
----------------------------------------------
-
作者:
男 yangshuo (海豚) ★☆☆☆☆ -
盒子活跃会员
2004/3/8 11:42:34
1楼: 当然可以调用,但不是你这样的用法.
首先一个thread在建立的时候,你最好把所有相关的参数都传进去.在你的例子中,你应该把form1的实例传进去,因此,你要修改你的线程的建立过程.
第二,在线程中调用过程,你最好间接的调用,也就是先建立一个线程内部的过程,无参数的.然后在这个过程中在调用你的form1的那个过程.使用同步关键字.
Synchronize(.....);你自己看帮助吧.


----------------------------------------------
delphi的忠实拥戴者
一起交流DELPHI
MSN: tech@delphisoft.com.cn
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS