barthread.pas

来自「详细说明:毕业论文中关于小型宾馆管理系统的详细设计毕 业论文中关于小型宾馆...」· PAS 代码 · 共 91 行

PAS
91
字号
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 + =
减小字号Ctrl + -
显示快捷键?