备份:
unit Unit1;interfaceuses
ShellAPI, FileCtrl,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls, ExtCtrls, DB, DBTables, DBConsts, DbiTypes, DbiProcs, DbiErrs;
type
Tbackup_form = class(TForm)
Panel1: TPanel;
Label1: TLabel;
edtToDir: TEdit;
spbtnGetToDir: TSpeedButton;
Button1: TButton;
Button2: TButton;
procedure spbtnGetToDirClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
backup_form: Tbackup_form;implementation{$R *.DFM}// 取得 Alias 的实际路径
function GetAliasPath(const sAliasName: string): string;
var
szName: array[0..100] of char;
Desc: DBDesc;
wResult: DBIResult;
begin
Result := '';
StrPLCopy(szName, sAliasName, High(szName));
wResult := DbiGetDatabaseDesc(szName, @Desc);
if wResult = DBIERR_NONE then
Result := StrPas(Desc.szPhyName);
end;function GetDirectory: String;
begin
if not SelectDirectory(Result, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
Result := EmptyStr;
end;procedure CopyDirectoryTree(AHandle: THandle; const AFromDirectory, AToDirectory: String);
var
SHFileOpStruct: TSHFileOpStruct;
FromDir: PChar;
ToDir: PChar;
begin GetMem(FromDir, Length(AFromDirectory)+2);
try
GetMem(ToDir, Length(AToDirectory)+2);
try FillChar(FromDir^, Length(AFromDirectory)+2, 0);
FillChar(ToDir^, Length(AToDirectory)+2, 0); StrCopy(FromDir, PChar(AFromDirectory));
StrCopy(ToDir, PChar(AToDirectory)); with SHFileOpStruct do
begin
Wnd := AHandle; // Assign the window handle
wFunc := FO_COPY; // Specify a file copy
pFrom := FromDir;
pTo := ToDir;
fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
end;
finally
FreeMem(ToDir, Length(AToDirectory)+2);
end;
finally
FreeMem(FromDir, Length(AFromDirectory)+2);
end;
end;procedure Tbackup_form.spbtnGetToDirClick(Sender: TObject);
begin
edtToDir.Text := GetDirectory;
end;procedure Tbackup_form.Button1Click(Sender: TObject);
var Aliaspath:string;
begin
if edttodir.Text ='' then
begin
showmessage('请输入或选择路径!');
end
else
begin
Aliaspath:= GetAliasPath('myalias');
CopyDirectoryTree(Handle, Aliaspath, edtToDir.Text);
showmessage('备份完毕!');
close;
end
end;procedure Tbackup_form.Button2Click(Sender: TObject);
begin
close;
end;end.恢复:
nit Unit2;interfaceuses
ShellAPI, FileCtrl,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls, ExtCtrls, DB, DBTables, DBConsts, DbiTypes, DbiProcs, DbiErrs;type
TRestore_Form = class(TForm)
Label1: TLabel;
Panel1: TPanel;
spbtnGetToDir: TSpeedButton;
edtToDir: TEdit;
Button1: TButton;
Button2: TButton;
procedure spbtnGetToDirClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Restore_Form: TRestore_Form;implementationuses Unit1;{$R *.DFM}// 取得 Alias 的实际路径
function GetAliasPath(const sAliasName: string): string;
var
szName: array[0..100] of char;
Desc: DBDesc;
wResult: DBIResult;
begin
Result := '';
StrPLCopy(szName, sAliasName, High(szName));
wResult := DbiGetDatabaseDesc(szName, @Desc);
if wResult = DBIERR_NONE then
Result := StrPas(Desc.szPhyName);
end;function GetDirectory: String;
begin
if not SelectDirectory(Result, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
Result := EmptyStr;
end;
procedure CopyDirectoryTree(AHandle: THandle; const AFromDirectory, AToDirectory: String);
var
SHFileOpStruct: TSHFileOpStruct;
FromDir: PChar;
ToDir: PChar;
begin GetMem(FromDir, Length(AFromDirectory)+2);
try
GetMem(ToDir, Length(AToDirectory)+2);
try FillChar(FromDir^, Length(AFromDirectory)+2, 0);
FillChar(ToDir^, Length(AToDirectory)+2, 0); StrCopy(FromDir, PChar(AFromDirectory));
StrCopy(ToDir, PChar(AToDirectory)); with SHFileOpStruct do
begin
Wnd := AHandle; // Assign the window handle
wFunc := FO_COPY; // Specify a file copy
pFrom := FromDir;
pTo := ToDir;
fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
end;
finally
FreeMem(ToDir, Length(AToDirectory)+2);
end;
finally
FreeMem(FromDir, Length(AFromDirectory)+2);
end;
end;
procedure TRestore_Form.spbtnGetToDirClick(Sender: TObject);
begin
edtToDir.Text := GetDirectory;
end;procedure TRestore_Form.Button1Click(Sender: TObject);
var Aliaspath:string;
begin
if edttodir.Text ='' then
begin
showmessage('请输入或选择路径!');
end
else
begin
Aliaspath:= GetAliasPath('myclass');
CopyDirectoryTree(Handle, edtToDir.Text,Aliaspath);
showmessage('恢复完毕!');
close;
end
end;procedure TRestore_Form.Button2Click(Sender: TObject);
begin
close;
end;procedure TRestore_Form.FormActivate(Sender: TObject);
begin
if messagedlg('恢复会覆盖原有的数据,请先备份!!!',mtWarning,[mbyes,mbno],0)<>mryes then
begin
restore_form.Close ;
end
else
begin
backup_form:=Tbackup_form.Create(Application);
if backup_form.ShowModal =mrok then
try
finally
backup_form.free;
backup_form:=nil;
end;
end
end;end.其中,别名你需要自己设置。
备份和恢复分别为两个窗体,你只需要把相应的组件放到窗体上去,再照着上面的代码写进去就可以了。
不过你的分好像少了一点吧?随便你了!就算是帮帮你吧!呵呵
unit Unit1;interfaceuses
ShellAPI, FileCtrl,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls, ExtCtrls, DB, DBTables, DBConsts, DbiTypes, DbiProcs, DbiErrs;
type
Tbackup_form = class(TForm)
Panel1: TPanel;
Label1: TLabel;
edtToDir: TEdit;
spbtnGetToDir: TSpeedButton;
Button1: TButton;
Button2: TButton;
procedure spbtnGetToDirClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
backup_form: Tbackup_form;implementation{$R *.DFM}// 取得 Alias 的实际路径
function GetAliasPath(const sAliasName: string): string;
var
szName: array[0..100] of char;
Desc: DBDesc;
wResult: DBIResult;
begin
Result := '';
StrPLCopy(szName, sAliasName, High(szName));
wResult := DbiGetDatabaseDesc(szName, @Desc);
if wResult = DBIERR_NONE then
Result := StrPas(Desc.szPhyName);
end;function GetDirectory: String;
begin
if not SelectDirectory(Result, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
Result := EmptyStr;
end;procedure CopyDirectoryTree(AHandle: THandle; const AFromDirectory, AToDirectory: String);
var
SHFileOpStruct: TSHFileOpStruct;
FromDir: PChar;
ToDir: PChar;
begin GetMem(FromDir, Length(AFromDirectory)+2);
try
GetMem(ToDir, Length(AToDirectory)+2);
try FillChar(FromDir^, Length(AFromDirectory)+2, 0);
FillChar(ToDir^, Length(AToDirectory)+2, 0); StrCopy(FromDir, PChar(AFromDirectory));
StrCopy(ToDir, PChar(AToDirectory)); with SHFileOpStruct do
begin
Wnd := AHandle; // Assign the window handle
wFunc := FO_COPY; // Specify a file copy
pFrom := FromDir;
pTo := ToDir;
fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
end;
finally
FreeMem(ToDir, Length(AToDirectory)+2);
end;
finally
FreeMem(FromDir, Length(AFromDirectory)+2);
end;
end;procedure Tbackup_form.spbtnGetToDirClick(Sender: TObject);
begin
edtToDir.Text := GetDirectory;
end;procedure Tbackup_form.Button1Click(Sender: TObject);
var Aliaspath:string;
begin
if edttodir.Text ='' then
begin
showmessage('请输入或选择路径!');
end
else
begin
Aliaspath:= GetAliasPath('myalias');
CopyDirectoryTree(Handle, Aliaspath, edtToDir.Text);
showmessage('备份完毕!');
close;
end
end;procedure Tbackup_form.Button2Click(Sender: TObject);
begin
close;
end;end.恢复:
nit Unit2;interfaceuses
ShellAPI, FileCtrl,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ComCtrls, ExtCtrls, DB, DBTables, DBConsts, DbiTypes, DbiProcs, DbiErrs;type
TRestore_Form = class(TForm)
Label1: TLabel;
Panel1: TPanel;
spbtnGetToDir: TSpeedButton;
edtToDir: TEdit;
Button1: TButton;
Button2: TButton;
procedure spbtnGetToDirClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Restore_Form: TRestore_Form;implementationuses Unit1;{$R *.DFM}// 取得 Alias 的实际路径
function GetAliasPath(const sAliasName: string): string;
var
szName: array[0..100] of char;
Desc: DBDesc;
wResult: DBIResult;
begin
Result := '';
StrPLCopy(szName, sAliasName, High(szName));
wResult := DbiGetDatabaseDesc(szName, @Desc);
if wResult = DBIERR_NONE then
Result := StrPas(Desc.szPhyName);
end;function GetDirectory: String;
begin
if not SelectDirectory(Result, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
Result := EmptyStr;
end;
procedure CopyDirectoryTree(AHandle: THandle; const AFromDirectory, AToDirectory: String);
var
SHFileOpStruct: TSHFileOpStruct;
FromDir: PChar;
ToDir: PChar;
begin GetMem(FromDir, Length(AFromDirectory)+2);
try
GetMem(ToDir, Length(AToDirectory)+2);
try FillChar(FromDir^, Length(AFromDirectory)+2, 0);
FillChar(ToDir^, Length(AToDirectory)+2, 0); StrCopy(FromDir, PChar(AFromDirectory));
StrCopy(ToDir, PChar(AToDirectory)); with SHFileOpStruct do
begin
Wnd := AHandle; // Assign the window handle
wFunc := FO_COPY; // Specify a file copy
pFrom := FromDir;
pTo := ToDir;
fFlags := FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted := False;
hNameMappings := nil;
lpszProgressTitle := nil;
if SHFileOperation(SHFileOpStruct) <> 0 then
RaiseLastWin32Error;
end;
finally
FreeMem(ToDir, Length(AToDirectory)+2);
end;
finally
FreeMem(FromDir, Length(AFromDirectory)+2);
end;
end;
procedure TRestore_Form.spbtnGetToDirClick(Sender: TObject);
begin
edtToDir.Text := GetDirectory;
end;procedure TRestore_Form.Button1Click(Sender: TObject);
var Aliaspath:string;
begin
if edttodir.Text ='' then
begin
showmessage('请输入或选择路径!');
end
else
begin
Aliaspath:= GetAliasPath('myclass');
CopyDirectoryTree(Handle, edtToDir.Text,Aliaspath);
showmessage('恢复完毕!');
close;
end
end;procedure TRestore_Form.Button2Click(Sender: TObject);
begin
close;
end;procedure TRestore_Form.FormActivate(Sender: TObject);
begin
if messagedlg('恢复会覆盖原有的数据,请先备份!!!',mtWarning,[mbyes,mbno],0)<>mryes then
begin
restore_form.Close ;
end
else
begin
backup_form:=Tbackup_form.Create(Application);
if backup_form.ShowModal =mrok then
try
finally
backup_form.free;
backup_form:=nil;
end;
end
end;end.其中,别名你需要自己设置。
备份和恢复分别为两个窗体,你只需要把相应的组件放到窗体上去,再照着上面的代码写进去就可以了。
不过你的分好像少了一点吧?随便你了!就算是帮帮你吧!呵呵
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货