📄 barthread.pas
字号:
unit Barthread;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls;
type
TBarThread = Class (TThread)
private
{ Private declarations }
FIdx:integer;
FBar:TProgressBar;
Procedure RefreshBar;
protected
Procedure Execute;Override;
public
{ Public declarations }
Constructor Create(lbar:TProgressBar);
procedure sysDelay(aMs: Longint);
end;
implementation
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TBarThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TBarThread }
Procedure TBarThread.RefreshBar;
begin
Fbar.Position:=Fidx;
sysdelay(300);
if Fidx=100 then begin
Fbar.Position:=0;
Execute;
end;
end;
// Execute
Procedure TBarThread.Execute;
var
idx:integer;
begin
for idx:=1 to 100 do begin
Fidx:=idx;
synchronize(RefreshBar);
//sysDelay(6000);
if Terminated then Exit;
end;
end;
// Create
Constructor TBarThread.Create(lbar:TProgressbar);
begin
inherited Create(False);
FBar:=lbar;
FreeOnTerminate:=True;
end;
//Delay
procedure TBarThread.sysDelay(aMs: Longint);
var
TickCount : LongInt;
begin
TickCount:=GetTickCount;
while GetTickCount - TickCount < aMs do Application.ProcessMessages;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -