singlesizethreadunit.pas

来自「软件可自动完成SQL Server数据库和文档的数据定时自动备份」· PAS 代码 · 共 60 行

PAS
60
字号
unit SingleSizeThreadUnit;

interface

uses
  Classes, SysUtils;

type
  TSingleSizeThread = class(TThread)
  private
    { Private declarations }
    sFileName:String;

    procedure GetSingleFileSize;
  protected
    procedure Execute; override;
  public
    constructor Create(_sFileName:String);
  end;

implementation

{ 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 TSingleSizeThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TSingleSizeThread }
uses
  FileTestUnit, TestFunctionUnit;
constructor TSingleSizeThread.Create(_sFileName:String);
begin
  sFileName:=_sFileName;
  inherited Create(True);
end;

procedure TSingleSizeThread.GetSingleFileSize;
var
  getStr:String;
begin
  getStr:=DateTimeToStr(now)+','+ExtractFileName(sFileName)+' 的大小为:'+FormatFloat('#,##0.00',GetFileSize(sFileName))+'KB';
  FileTestForm.ListBox1.Items.Add(getStr);
end;

procedure TSingleSizeThread.Execute;
begin
  { Place thread code here }
  FreeOnTerminate:=True;
  synchronize(GetSingleFileSize);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?