如何在一个窗体中动态创建一个线程,这个线程的工作就是不停的更新该窗体的某个label或者其他控件的的内容 如何在一个窗体中动态创建一个线程,这个线程的工作就是不停的更新该窗体的某个label或者其他控件的的内容 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit Unit2;interfaceuses Classes,StdCtrls,SysUtils;type test = class(TThread) private { Private declarations } FLabel: TLabel; public Constructor Create(aLabel: TLabel); protected procedure Execute; override; end;implementation{ test }constructor test.Create(aLabel: TLabel);begin FLabel:=aLabel; inherited Create(false);end;procedure test.Execute;begin while not Terminated do begin self.FLabel.Caption:=DateTimeToStr(Now); sleep(1000); end; { Place thread code here }end;end.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,shellapi, StdCtrls,Unit2;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } t:test; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin t:= test.Create(self.Label1);end;procedure TForm1.Button2Click(Sender: TObject);begint.Terminate;end;end. unit Unit2;interfaceuses Classes,StdCtrls,SysUtils;type test = class(TThread) private { Private declarations } public procedure Fresh; protected procedure Execute; override; end;implementationuses Unit1;{ test }procedure test.Fresh;begin Form1.Label1.Caption := DateTimeToStr(Now);end;procedure test.Execute;begin while not Terminated do begin WaitForSingleObject(Event, 1000); Synchronize(Fresh); end;end;end.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,shellapi, StdCtrls, Unit2;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } t:test; public { Public declarations } end;var Form1: TForm1; Event: THandle;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin Event := CreateEvent(nil, false, false, nil); SetEvent(Event);end;procedure TForm1.Button1Click(Sender: TObject);begin t:= test.Create(false);end;procedure TForm1.Button2Click(Sender: TObject);begin if not t.Terminated then begin SetEvent(Event); t.Terminate; t.WaitFor; t.Free; end;end; 就是在执行线程显示后,再执行select 语句(只是提取的内容很多), To:玉米老兄!您写得比较规范,但我有一个问题请教您:在设计期已经确定用单线程来访问的控件还用加Synchronize吗?我认为如果在UI线程中该控件仅仅是显示,而不参与修改的话,是不是直接将其的引用传到线程中更好一些! Delphi中地址的写法 分就是拿来散的。 毕业设计问题 怎么编写SQL语句去掉多余的空格 Cb++的原形怎么转为DELPHI 其中用一个CString类型。难了,请大家多帮忙. Excel打印输出遇到问题。请看看错在哪里。这个号没分了,解决的朋友,我用其它号给分。 请问不使用第三组件怎样打印 grid的内容,现在希望可以学习继承类的方法去实现这功能 如何在WIN2K里传送控制台消息 编程停止已经启动的远程访问服务 关于TABLE的记录过滤问题? 谁能介绍一些关于AD0连接数据库的范列??? 请教控件复制(创建) 帮忙看下这段语句怎么改
Classes,StdCtrls,SysUtils;type
test = class(TThread)
private
{ Private declarations }
FLabel: TLabel;
public
Constructor Create(aLabel: TLabel);
protected
procedure Execute; override;
end;implementation{ test }constructor test.Create(aLabel: TLabel);
begin
FLabel:=aLabel;
inherited Create(false);
end;procedure test.Execute;
begin
while not Terminated do
begin
self.FLabel.Caption:=DateTimeToStr(Now);
sleep(1000);
end;
{ Place thread code here }
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls,Unit2;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
t:test;
public
{ Public declarations }
end;var
Form1: TForm1;implementation
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
t:= test.Create(self.Label1);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
t.Terminate;
end;end.
unit Unit2;interfaceuses
Classes,StdCtrls,SysUtils;type
test = class(TThread)
private
{ Private declarations }
public
procedure Fresh;
protected
procedure Execute; override;
end;implementationuses Unit1;{ test }procedure test.Fresh;
begin
Form1.Label1.Caption := DateTimeToStr(Now);
end;procedure test.Execute;
begin
while not Terminated do
begin
WaitForSingleObject(Event, 1000);
Synchronize(Fresh);
end;
end;end.unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, StdCtrls, Unit2;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
t:test;
public
{ Public declarations }
end;var
Form1: TForm1;
Event: THandle;implementation
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Event := CreateEvent(nil, false, false, nil);
SetEvent(Event);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
t:= test.Create(false);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if not t.Terminated then
begin
SetEvent(Event);
t.Terminate;
t.WaitFor;
t.Free;
end;
end;