我用copyfile做的access的保存,其间用到了opendilalog,savedialog,本意是将open的文件修改后另存的,文件可复制,但delphi老报错“unsafe type ‘pchar’”,有哪位知道是什么意思么?单独别的用话程序是不报错的,但用在我的程序中就报这个错,郁闷啊!!郁闷啊!!!
我的email是[email protected]
求各位帮帮忙介绍一下copyfile的具体用法,最好能有关于opendialog和savedialog的保存源码,邮寄给我,不胜感激。。已下为源码,请各位指点一下
procedure Tmainform.N32Click(Sender: TObject);//access数据库的打开
var
myaccess:string;
const
link_str='Provider=%s; Data Source=%s';
dataprovider='microsoft.jet.oledb.4.0';begin
opendialog1.FileName :='*.mdb';
if opendialog1.Execute then
begin
myaccess:=opendialog1.FileName;
edit1.Text :=myaccess ;
alldata.adoconnection1.Connected :=false;
alldata.adoconnection1.ConnectionString :=format(link_str,[dataprovider,myaccess]);
alldata.ADOConnection1.connected:=true;
alldata.ADOTable2.Active:=true;
alldata.ADOQuery2.Active:=true;
end;
end;procedure Tmainform.N33Click(Sender: TObject);//切断adoconection的联系
begin
alldata.ADOTable2.close;
alldata.ADOQuery2.Close;
alldata.ADOConnection1.Connected:=false;
edit2.Text:=edit1.Text;
edit1.Text:='';end;procedure Tmainform.N35Click(Sender: TObject);//我写的保存
var
EXEPATH:String;
access:string;
const
link_str='Provider=%s; Data Source=%s';
dataprovider='microsoft.jet.oledb.4.0';
begin
opendialog1.FileName :='*.mdb';
access:=opendialog1.FileName;
try
if not savedialog1.Execute then exit;
if FileExists(savedialog1.FileName+'.mdb') then
begin
if Messagebox(handle,'存在数据库重名,是否覆盖?','存盘选项',mb_iconquestion+mb_yesno)=IDNo then Exit;
end
else
begin
EXEPATH:=opendialog1.FileName;
CopyFile(PChar(edit2.text),PChar(SaveDialog1.FileName+'.mdb'),True);
Messagebox(handle,'数据库备份成功!','备份数据',mb_iconinformation+mb_ok);
end;
except
Messagebox(handle,'警告:数据库备份失败!','存盘错误',mb_iconwarning+mb_ok);
end;
end;
我的email是[email protected]
求各位帮帮忙介绍一下copyfile的具体用法,最好能有关于opendialog和savedialog的保存源码,邮寄给我,不胜感激。。已下为源码,请各位指点一下
procedure Tmainform.N32Click(Sender: TObject);//access数据库的打开
var
myaccess:string;
const
link_str='Provider=%s; Data Source=%s';
dataprovider='microsoft.jet.oledb.4.0';begin
opendialog1.FileName :='*.mdb';
if opendialog1.Execute then
begin
myaccess:=opendialog1.FileName;
edit1.Text :=myaccess ;
alldata.adoconnection1.Connected :=false;
alldata.adoconnection1.ConnectionString :=format(link_str,[dataprovider,myaccess]);
alldata.ADOConnection1.connected:=true;
alldata.ADOTable2.Active:=true;
alldata.ADOQuery2.Active:=true;
end;
end;procedure Tmainform.N33Click(Sender: TObject);//切断adoconection的联系
begin
alldata.ADOTable2.close;
alldata.ADOQuery2.Close;
alldata.ADOConnection1.Connected:=false;
edit2.Text:=edit1.Text;
edit1.Text:='';end;procedure Tmainform.N35Click(Sender: TObject);//我写的保存
var
EXEPATH:String;
access:string;
const
link_str='Provider=%s; Data Source=%s';
dataprovider='microsoft.jet.oledb.4.0';
begin
opendialog1.FileName :='*.mdb';
access:=opendialog1.FileName;
try
if not savedialog1.Execute then exit;
if FileExists(savedialog1.FileName+'.mdb') then
begin
if Messagebox(handle,'存在数据库重名,是否覆盖?','存盘选项',mb_iconquestion+mb_yesno)=IDNo then Exit;
end
else
begin
EXEPATH:=opendialog1.FileName;
CopyFile(PChar(edit2.text),PChar(SaveDialog1.FileName+'.mdb'),True);
Messagebox(handle,'数据库备份成功!','备份数据',mb_iconinformation+mb_ok);
end;
except
Messagebox(handle,'警告:数据库备份失败!','存盘错误',mb_iconwarning+mb_ok);
end;
end;
解决方案 »
- 把“Edit1”中的文本增加到“ListBox1”中遇到的问题!
- 打印
- 在三层结构的ActiveForm中使用 ClientDataSet1.ApplyUpdates(0);更新不了的问题!请帮忙
- 大家都进来
- 寻找每个记录带一个checkbox的DBGrid构件?
- 怎样备份数据库
- 挑战智商:这个问题我已详细给图并说明,最关键的是红色字体部分不能解决,请大虾提供解决方法!!
- 帮忙看看为什么通不过?
- 有谁知道这个错误:OLE error 800A03EC?
- 在DEIPHI中如何调用WORD打开WORD文档
- ##################普通域用户用ADO如何访问域服务器中的SQL数据库########################
- 高分求救:使用indytcpserver报错,是怎么回事?在线等待结帖
var
MyFileName:string;
begin
MyFileName:= '';
try
SaveDialog1.DefaultExt:='.mdb';
SaveDialog1.Filter:= '数据库文件|*.mdb|所有文件|*.*';
if SaveDialog1.Execute then //FormatDateTime('yyyymmdd',now)
begin
MyFileName := SaveDialog1.FileName;
if MyFileName <> '' then
begin
if CopyFile(Pchar(ExtractFilePath(Application.ExeName)+'data.mdb'), Pchar(MyFileName), false) then
begin
msgshow('数据备份成功!');
end;
end;
end;
except
msgshow('数据备份失败!');
end;
end;
procedure TFrm_backup.BitBtn2Click(Sender: TObject);
var
MyFileName,aa:string;
begin
MyFileName:='';
try
openDialog1.DefaultExt:='.mdb';
openDialog1.Filter:= '数据库文件|*.mdb|所有文件|*.*';
if OpenDialog1.Execute then
begin
MyFileName:=OpenDialog1.FileName;
if MyFileName <> '' then
begin
aa:=Extractfilepath(ParamStr(0))+'data.mdb';
if CopyFile(Pchar(MyFileName),Pchar(aa), false) then
begin
adom.ADOConnection1.Close;
adom.ADOConnection1.Open;
msgshow('数据恢复成功,请您重新进入系统!');
end;
end;
end;
except
msgshow('数据恢复失败!');
end;end;