主题:[讨论]急!急!急!
我要实现数据库的备份与恢复,以下是原代码,程序运行通过,就是进入界面后,单击“恢复”按钮出现如下错误:project project1.exe raised exception class EAccessViolation with message'Access violication at address 7c84BF3A in module'kernel32.dll'.read of address EC6C0100'process stopped.
(我在该单元文件的USES里加入了:shellAPI)
哪为高手帮下忙,究竟是什么问题?原程序为:
procedure TForm13.Button2Click(Sender: TObject);
var
f:tshfileopstruct;
begin
f.wnd:=handle;
f.wfunc:=fo_delete;{操作方式}
f.pfrom:=pansichar(extractfiledir(application.ExeName)+'\db2.mdb'+#0#0);
f.fflags:=fof_allowundo or fof_renameoncollision;{操作选项}
{断开连接}
adoconnection1.Connected:=false;
if SHFileoperation(f)<>0 then [color=008080][color=0000FF][color=FF0000][b](程序在此运行出错)[/b][/color][/color][/color]
messagebox(0,'删除原始数据文件失败!','错误',mb_ok+mb_iconstop)
else
begin
opendialog1.Filter:='ACCESS 文件(*.mdb)|*.mdb';
OpenDialog1.InitialDir:=extractfiledir(application.ExeName)+'\backup';
OpenDialog1.Title:='选择备份文件';
if OpenDialog1.Execute then
if copyfile(pchar(opendialog1.FileName),pchar(extractfiledir(application.exename)
+'\db2.mdb'),false) then
messagebox(0,'数据文件恢复成功!','成功',mb_ok+mb_iconinformation);
{恢复连接}
adoconnection1.connected:=true;
end;
end;[em15][em15][em18][em19]
(我在该单元文件的USES里加入了:shellAPI)
哪为高手帮下忙,究竟是什么问题?原程序为:
procedure TForm13.Button2Click(Sender: TObject);
var
f:tshfileopstruct;
begin
f.wnd:=handle;
f.wfunc:=fo_delete;{操作方式}
f.pfrom:=pansichar(extractfiledir(application.ExeName)+'\db2.mdb'+#0#0);
f.fflags:=fof_allowundo or fof_renameoncollision;{操作选项}
{断开连接}
adoconnection1.Connected:=false;
if SHFileoperation(f)<>0 then [color=008080][color=0000FF][color=FF0000][b](程序在此运行出错)[/b][/color][/color][/color]
messagebox(0,'删除原始数据文件失败!','错误',mb_ok+mb_iconstop)
else
begin
opendialog1.Filter:='ACCESS 文件(*.mdb)|*.mdb';
OpenDialog1.InitialDir:=extractfiledir(application.ExeName)+'\backup';
OpenDialog1.Title:='选择备份文件';
if OpenDialog1.Execute then
if copyfile(pchar(opendialog1.FileName),pchar(extractfiledir(application.exename)
+'\db2.mdb'),false) then
messagebox(0,'数据文件恢复成功!','成功',mb_ok+mb_iconinformation);
{恢复连接}
adoconnection1.connected:=true;
end;
end;[em15][em15][em18][em19]