procedure TfrmMain.Button1Click(Sender: TObject);
var
p : string;
begin
  p:='c:\';
  OpenDialog1.FileName :='';
  OpenDialog1.InitialDir := P;
  if OpenDialog1.Execute then
    P := ExtractFilePath(OpenDialog1.FileName);
if copyfile('GZ.mdb',p,false)  then //这一句报错~~[Error] FMain.pas(1241): Incompatible types: 'String' and 'PAnsiChar'
 application.MessageBox('数据恢复成功','恢复数据',mb_ok)
 else
  application.MessageBox('数据恢复失败','恢复数据',mb_ok);
end;
//copyfile('GZ.mdb',p,false) 
这一句报错,错误信息,类型不匹配~~不知应该怎样改呀~~
[Error] FMain.pas(1241): Incompatible types: 'String' and 'PAnsiChar'

解决方案 »

  1.   

    copyfile(PChar('GZ.mdb'),PChar(p),false) 
      

  2.   

    恢复应该是
    copyfile(PChar(p),PChar('GZ.mdb'),false) 
    应该还是路径有问题
    换成
    copyfile('backup\backupgz.mdb',PChar('GZ.mdb'),false) 
    就没问题
    可是这样子文件名和路径都是确定的~~该怎样改呢?
      

  3.   

    可以备份了,是EXtractFilePath 这个的问题~~!~~
    现在又出现另外的问题了~~
    不是备份到想要的路径下如何获取执行程序所在的路径呢?
      

  4.   

    AppPath := ExtractFilePath(Application.ExeName);
    DBPath := AppPath+ 'data\GZ.mdb';   \\数据库相对应用程序目录
    BackupPath := 'd:\backup.mdb';  \\设自己的备分目录,建议用 SelectFolderDialog1 可自动选择if not DirectoryExists(BackupPath) then
         showmessage('备份目录无效!');
    else begin
         CopyFile(pchar(DBPath),pchar(BackupPath),false);
         showmessage('备份成功!');
    end;    end;
      

  5.   

    if not DirectoryExists(BackupPath) then
         showmessage('备份目录无效!')
    else begin
         CopyFile(pchar(DBPath),pchar(BackupPath),false);
         showmessage('备份成功!');
    end;
      

  6.   

    搞定了
    Application.ExeName
    ParamStr(0)
    这两个都可以用~~
    谢谢啦~~