thrdu.pas
来自「一个关于delphi线程的范例,举例简单的线程使用例子.」· PAS 代码 · 共 62 行
PAS
62 行
unit ThrdU;
interface
uses
Classes;
type
TTestThread = class(TThread)
private
Answer:Integer;
{ Private declarations }
protected
procedure GiveAnswer;
procedure Execute; override;
end;
implementation
uses SysUtils,Unit1;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TTestThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TTestThread }
procedure TTestThread.GiveAnswer;
begin
Form1.Edit1.Text:=IntToStr(Answer);
end;
procedure TTestThread.Execute;
var
i:Integer;
begin
FreeOnTerminate:=True;
Form1.ProgressBar1.Max:=200000;
Form1.ProgressBar1.Position:=0;
for i:=1 to 200000 do
begin
if terminated then Break;
//Inc(Answer,Round(Abs(Sin(Sqrt(i)))));
Answer:=i;
Synchronize(GiveAnswer);
Form1.ProgressBar1.Position:=Form1.ProgressBar1.Position+1;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?