主题:帮忙看看下面的一段代码 谢谢了
unit Unit_copy;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls;
type
Tcopyform = class(TForm)
Label1: TLabel;
Edit1: TEdit;
BtnOpen: TSpeedButton;
BtnBackUp: TSpeedButton;
BtnClose: TSpeedButton;
Edit2: TEdit;
Label2: TLabel;
procedure BtnOpenClick(Sender: TObject);
procedure BtnBackUpClick(Sender: TObject);
procedure BtnCloseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
copyform: Tcopyform;
implementation
uses unit_main;
{$R *.dfm}
procedure Tcopyform.BtnOpenClick(Sender: TObject);
var
dir,root:string;
begin
root:=ExtractFileDir(paramstr(0));
if SelectDirectory('选择路径',root,Dir) then
edit1.Text:=Dir;
end;
procedure Tcopyform.BtnBackUpClick(Sender: TObject);
var
newpath,filename:string;
begin
btnclose.Enabled:=False;
filename:=edit2.text+'.bak';
newpath:=edit1.Text+'\'+filename;
if main.conn.Connected then
main.conn.Close;
if fileExists(newpath) then
begin
if application.MessageBox('数据备份已存在,是否覆盖?','提示',mb_okcancel)=ID_OK then
begin
main.adoquery1.Close;
try
with main.adoquery1 do
begin
main.adoquery1.close;
main.adoquery1.sql.Clear;
main.adoquery1.sql.add('backup database mhpc to disk=''newpath''');
execsql;
end;
showmessage('备份完成');
except
showmessage('备份失败');
end;
exit;
end;
main.adoquery1.Close;
try
with main.adoquery1 do
begin
main.adoquery1.close;
main.adoquery1.sql.Clear;
main.adoquery1.sql.add('backup database mhpc to disk=''newpath''');
execsql;
end;
showmessage('备份完成');
except
showmessage('备份失败');
end;
btnclose.Enabled:=true;
main.conn.Open();
end;
end;
procedure Tcopyform.BtnCloseClick(Sender: TObject);
begin
self.Close;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls;
type
Tcopyform = class(TForm)
Label1: TLabel;
Edit1: TEdit;
BtnOpen: TSpeedButton;
BtnBackUp: TSpeedButton;
BtnClose: TSpeedButton;
Edit2: TEdit;
Label2: TLabel;
procedure BtnOpenClick(Sender: TObject);
procedure BtnBackUpClick(Sender: TObject);
procedure BtnCloseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
copyform: Tcopyform;
implementation
uses unit_main;
{$R *.dfm}
procedure Tcopyform.BtnOpenClick(Sender: TObject);
var
dir,root:string;
begin
root:=ExtractFileDir(paramstr(0));
if SelectDirectory('选择路径',root,Dir) then
edit1.Text:=Dir;
end;
procedure Tcopyform.BtnBackUpClick(Sender: TObject);
var
newpath,filename:string;
begin
btnclose.Enabled:=False;
filename:=edit2.text+'.bak';
newpath:=edit1.Text+'\'+filename;
if main.conn.Connected then
main.conn.Close;
if fileExists(newpath) then
begin
if application.MessageBox('数据备份已存在,是否覆盖?','提示',mb_okcancel)=ID_OK then
begin
main.adoquery1.Close;
try
with main.adoquery1 do
begin
main.adoquery1.close;
main.adoquery1.sql.Clear;
main.adoquery1.sql.add('backup database mhpc to disk=''newpath''');
execsql;
end;
showmessage('备份完成');
except
showmessage('备份失败');
end;
exit;
end;
main.adoquery1.Close;
try
with main.adoquery1 do
begin
main.adoquery1.close;
main.adoquery1.sql.Clear;
main.adoquery1.sql.add('backup database mhpc to disk=''newpath''');
execsql;
end;
showmessage('备份完成');
except
showmessage('备份失败');
end;
btnclose.Enabled:=true;
main.conn.Open();
end;
end;
procedure Tcopyform.BtnCloseClick(Sender: TObject);
begin
self.Close;
end;
end.