程序在打包安装运行后,生成一桌面图标,点它运行后,然后想备份数据的话,结果只在桌面生成了一个 备份数据文件夹,是不是说明它得到的路径就是桌面了,这是怎么回事,很困惑,只有安在C盘出现这种状况,如果点击其.exe运行的话没也问题,下面是备份的代码
procedure TForm12.BitBtn1Click(Sender: TObject);
var
failure :boolean;
path:string;
begin
failure:=false;
path:=mypath;
if not FileExists(path+'\备份数据') then
createdir('备份数据');
if not copyfile('data\db2.mdb','备份数据\db2.mdb',false) then
failure:=true;
if failure then
ShowMessage('数据备份没有成功!')
else
ShowMessage('数据备份结束!');
end ;procedure TForm1.FormCreate(Sender: TObject);//form1中定义的全局变量,unit12中有引用unit1
begin
mypath:= ExtractFilePath(Application.ExeName);//获得当前程序路径
end;
procedure TForm12.BitBtn1Click(Sender: TObject);
var
failure :boolean;
path:string;
begin
failure:=false;
path:=mypath;
if not FileExists(path+'\备份数据') then
createdir('备份数据');
if not copyfile('data\db2.mdb','备份数据\db2.mdb',false) then
failure:=true;
if failure then
ShowMessage('数据备份没有成功!')
else
ShowMessage('数据备份结束!');
end ;procedure TForm1.FormCreate(Sender: TObject);//form1中定义的全局变量,unit12中有引用unit1
begin
mypath:= ExtractFilePath(Application.ExeName);//获得当前程序路径
end;
改成
if not copyfile(path+'\data\db2.mdb',path+'\备份数据\db2.mdb',false) then
procedure TForm12.BitBtn1Click(Sender: TObject);
var
failure :boolean;
path:string;
begin
failure:=false;
path:=mypath;
if not DirectoryExists(path+'\备份数据') then
createdir(path+'\备份数据'); if not copyfile(path+'\data\db2.mdb',path+'\备份数据\db2.mdb',false) then
failure:=true;
if failure then
ShowMessage('数据备份没有成功!')
else
ShowMessage('数据备份结束!');
end ;
都是用全路径来处理
Unit12.pas(68): Incompatible types: 'String' and 'PAnsiChar',
给path加上单引号后不报错了,但是程序运行时什么状态下都不能备份了,