📄 gaugep.pas
字号:
unit GaugeP;
interface
uses
Classes, comctrls,Gauges;
type
TGaugeThread = class(TThread)
private
Gauge : TGauge; // Reference to ProgressBar
procedure InitGauge; // Setup ProgressBar
procedure UpdateGauge; // Update ProgressBar
protected
procedure Execute; override; // Main thread execution
published
constructor CreateIt(PriorityLevel: cardinal;MHeight:Integer; GaugeBar : TGauge);
destructor Destroy; override;
end;
implementation
uses
windows, SendCommand;
constructor TGaugeThread.CreateIt(PriorityLevel: cardinal; MHeight:Integer; GaugeBar : TGauge);
begin
inherited Create(true); // Create thread suspended
Priority :=tpHigher; //TThreadPriority(PriorityLevel); // Set Priority Level
FreeOnTerminate := true; // Thread Free Itself when terminated
Gauge := GaugeBar; // Set reference
Synchronize(InitGauge); // Setup the ProgressBar
Suspended := false; // Continue the thread
end;
destructor TGaugeThread.Destroy;
begin
PostMessage(frmSendCommand.Handle,wm_ThreadDoneMsg,self.ThreadID,0);
inherited destroy;
end;
procedure TGaugeThread.Execute; // Main execution for thread
begin
while not Terminated do
begin
Synchronize(UpdateGauge); // Update ProgressBar, uses sychronize because ProgressBar is in another thread
// if Terminated is true, this loop exits prematurely so the thread will terminate
end;
end;
procedure TGaugeThread.InitGauge(); // setup/initialize the ProgressBar
begin
Gauge.MinValue := 0; // minimum value for bar
Gauge.MaxValue := MHeight; // maximum value for bar
// size will be used by each call to StepIt
Gauge.Progress := 0; // set position to begining
end;
procedure TGaugeThread.UpdateGauge; // Updates the ProgressBar
begin
Gauge.Progress:=ThreadHeight; // step the bar
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -