var MyFileName: string; begin MyFileName := ''; try if dlgSave1.Execute then begin MyFileName := dlgSave1.FileName; if MyFileName <> '' then begin if CopyFile(Pchar(ExtractFilePath(Application.ExeName) + 'SmartCash.mdb'), Pchar(MyFileName), false) then begin Application.MessageBox('数据备份成功','提示',Mb_ok + mb_iconinformation); end; end; end; except Application.MessageBox('数据备份失败','提示',Mb_ok + mb_iconError); end; 我测过,打开也能复制 dlgSave1的缺省扩展名为MDB
To:elite01(极度) 不行啊,兄弟,你把你这段代码写在定时器里面,然后在复制之前加上删除 DeleteFile('C:\Documents and Settings\fg.FUGANG\My Documents\temp\DB2005.mdb'); 你在测试一下就明白了,是不行的
正在用的时候怎么删除?除非你把正在用的MDB表关了再说
给你一个复制的代码! procedure NetFileCopy(SourceFile,MoveToFile:string;P:TRzProgressBar); var FromF, ToF: file; NumRead, NumWritten: Integer; Buf: array[1..2048] of Char; begin AssignFile(FromF, MoveToFile); Reset(FromF, 1); { Record size = 1 } AssignFile(ToF,SourceFile); { Open output file } Rewrite(ToF, 1); { Record size = 1 } P.PartsComplete:=0; P.TotalParts:=sizeof(FromF); repeat BlockRead(FromF, Buf, SizeOf(Buf), NumRead); BlockWrite(ToF, Buf, NumRead, NumWritten); P.IncPartsByOne; until (NumRead = 0) or (NumWritten <> NumRead); CloseFile(FromF); CloseFile(ToF); P.PartsComplete:=0; end;
我是删除掉刚刚复制的那个 DeleteFile('C:\Documents and Settings\My Documents\temp\SmartCash.mdb');
MyFileName: string;
begin
MyFileName := '';
try
if dlgSave1.Execute then
begin
MyFileName := dlgSave1.FileName;
if MyFileName <> '' then
begin
if CopyFile(Pchar(ExtractFilePath(Application.ExeName) + 'SmartCash.mdb'), Pchar(MyFileName), false) then
begin
Application.MessageBox('数据备份成功','提示',Mb_ok + mb_iconinformation);
end;
end;
end;
except
Application.MessageBox('数据备份失败','提示',Mb_ok + mb_iconError);
end;
我测过,打开也能复制
dlgSave1的缺省扩展名为MDB
不行啊,兄弟,你把你这段代码写在定时器里面,然后在复制之前加上删除
DeleteFile('C:\Documents and Settings\fg.FUGANG\My Documents\temp\DB2005.mdb');
你在测试一下就明白了,是不行的
procedure NetFileCopy(SourceFile,MoveToFile:string;P:TRzProgressBar);
var
FromF, ToF: file;
NumRead, NumWritten: Integer;
Buf: array[1..2048] of Char;
begin
AssignFile(FromF, MoveToFile);
Reset(FromF, 1); { Record size = 1 } AssignFile(ToF,SourceFile); { Open output file }
Rewrite(ToF, 1); { Record size = 1 } P.PartsComplete:=0;
P.TotalParts:=sizeof(FromF);
repeat
BlockRead(FromF, Buf, SizeOf(Buf), NumRead);
BlockWrite(ToF, Buf, NumRead, NumWritten);
P.IncPartsByOne;
until (NumRead = 0) or (NumWritten <> NumRead);
CloseFile(FromF);
CloseFile(ToF);
P.PartsComplete:=0;
end;
DeleteFile('C:\Documents and Settings\My Documents\temp\SmartCash.mdb');