📄 singletransferthreadunit.pas
字号:
unit SingleTransferThreadUnit;
interface
uses
Classes, SysUtils, Windows;
type
TSingleTransferThread = class(TThread)
private
{ Private declarations }
sFileName:String;
aDirName:String;
procedure SingleCopyDone;
protected
procedure Execute; override;
public
constructor Create(_sFileName,_aDirName: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 TSingleTransferThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TSingleTransferThread }
uses
TestFunctionUnit, FileTestUnit;
constructor TSingleTransferThread.Create(_sFileName,_aDirName:String);
begin
sFileName:=_sFileName;
aDirName:=_aDirName;
inherited Create(True);
end;
procedure TSingleTransferThread.SingleCopyDone;
var
noError:Boolean;
begin
noError:=True;
try
if not CopyFile(PChar(sFileName),PChar(aDirName+'\'+ExtractFileName(sFileName)),False) then
noError:=False;
except
if not SendFile(sFileName,aDirName+'\'+ExtractFileName(sFileName)) then
noError:=False;
end;
if noError then
FileTestForm.ListBox1.Items.Add('###'+sFileName)
else
FileTestForm.ListBox1.Items.Add('***'+sFileName);
end;
procedure TSingleTransferThread.Execute;
begin
{ Place thread code here }
FreeOnTerminate:=True;
synchronize(SingleCopyDone);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -