把实现文件拷贝过程的程序段(或函数调用)加入到onClose事件中。附:
procedure TForm1.CopyFile;
var
ShFileOpStruct: TShFileOpStruct;
begin
with ShFileOpStruct do
begin
wFunc := FO_COPY;
pFrom := PChar('c:\windows\test.exe');
pTo := PChar('myfile.exe');
end;
SHFileOperation(ShFileOpStruct);
end;
procedure TForm1.CopyFile;
var
ShFileOpStruct: TShFileOpStruct;
begin
with ShFileOpStruct do
begin
wFunc := FO_COPY;
pFrom := PChar('c:\windows\test.exe');
pTo := PChar('myfile.exe');
end;
SHFileOperation(ShFileOpStruct);
end;
pFrom和pTo需要双#0结尾的!
begin
copyfile('c:\grt2101', dir, false);//copyfile是delphi自己带的函数
sleep(3000) //等待三秒
end;
列程:
procedure Tfrm1.FormClose(Sender: TObject; var CanClose: Boolean);
Begin
CopyFile('C:\1.txt','D:\3.txt',False);
End;