请教copyfile的用法。在线等待!!:) edit1 edit2的值中已经包括了目录和文件名.如:c:\my docments\aaa.mdb 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 edit1.text:=opendialog1.filename;这样Edit1.text取到的包括路径!在copyfile(pchar(edit1.text),pchar(edit2.text),false); edit1.text:=opendialog1.filename;这样Edit1.text取到的包括路径!在copyfile(pchar(edit1.text),pchar(edit2.text),false); edit1.text:=opendialog1.filename;edit2.text:=savedialog1.filename;copyfile(pchar(edit1.text),pchar(edit2.text),false); copyfile(pchar(edit1.text),pchar(edit2.text),false);可是这样执行了以后,还是没有将edit1.text的文件复制到edit2.text的位置。为什么呀!不解呀... 太痛苦了!!! 我用的都是copyfileto(filestr1,filestr2),返回boolean效果不错! copyfileto(filestr1,filestr2),返回boolean,true成功!false失败! copyfile 和copyfileto有什么不一样. 没什么不一样!copyfileto需要idglobal的单元好象!用过很多次,不错! var filename:string;//目标库文件名 source,target: TFileStream; begin source:=TFileStream.Create('源库文件名',fmOpenRead );//支持路径、扩展名; try target:=TFileStream.Create(filename,fmOpenWrite or fmCreate); try if target.CopyFrom(source,source.Size)=source.Size then ShowMessage('成功备份到'+filename+'!!!'); finally target.Free; end; finally source.Free; end; var filename:string;//目标库文件名 source,target: TFileStream; begin source:=TFileStream.Create('源库文件名',fmOpenRead );//支持路径、扩展名; try target:=TFileStream.Create(filename,fmOpenWrite or fmCreate); try if target.CopyFrom(source,source.Size)=source.Size then ShowMessage('成功备份到'+filename+'!!!'); finally target.Free; end; finally source.Free; end; 可以的,我刚使了!!unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begincopyfile(pchar(edit1.text),pchar(edit2.text),false);end;procedure TForm1.Button2Click(Sender: TObject);begin if opendialog1.Execute then edit1.Text:=opendialog1.FileName;end;procedure TForm1.Button3Click(Sender: TObject);begin if savedialog1.Execute then edit2.Text:=savedialog1.FileName;end;end. 你的意思是拷贝文件还是拷贝字符串???edit2.text:=copy(edit1.text,1,length(edit1.text)); 我试了一下,源程序没有问题,放在其他目录可以复制的。但是放在正在运行的程序目录下(已有.mdb)确不复制成功。查看了一下,原因可能是我用ado连接的mdb数据库文件,程序在运行时已在程序目录下产生一个数据库锁定文件,现在是如何将锁定文件关闭,并执行复制过程呀!。 : linx88(haozi) ( ) edit1.text:=opendialog1.filename;edit2.text:=savedialog1.filename;copyfile(pchar(edit1.text),pchar(edit2.text),false); 用ado连接mdb数据库文件,只要有任何连接,都不能复制文件,我这也遇到过这问题,先将所有的连接断开。 DELPHI中调用带有日期型参数的存储过程 Delphi开发票据打印软件 delphi--廉颇已老? 打印时如何将内容在MEMO中居中? 双向链表的类,不知道怎么用法 HELP ME!谁有类似于XLGrid,或用友TCELL的控件 100分请高手赐教:这个项目我该怎么去架构?? 查找某一字符串中某一子字符串的所在位置,如Vb中的Instr函数 TCustomWinSocket.SendBuf和SendStream有什么区别 各位兄弟請幫幫忙,關于SQL的 初级问题,请高手指点,在线等待 sql中能不能进行日期的比较?送分,别见笑
这样Edit1.text取到的包括路径!
在copyfile(pchar(edit1.text),pchar(edit2.text),false);
这样Edit1.text取到的包括路径!
在copyfile(pchar(edit1.text),pchar(edit2.text),false);
edit2.text:=savedialog1.filename;
copyfile(pchar(edit1.text),pchar(edit2.text),false);
可是这样执行了以后,还是没有将edit1.text的文件复制到edit2.text的位置。
为什么呀!
不解呀... 太痛苦了!!!
效果不错!
有什么不一样.
用过很多次,不错!
filename:string;//目标库文件名
source,target: TFileStream;
begin
source:=TFileStream.Create('源库文件名',fmOpenRead );//支持路径、扩展名;
try
target:=TFileStream.Create(filename,fmOpenWrite or fmCreate);
try
if target.CopyFrom(source,source.Size)=source.Size then
ShowMessage('成功备份到'+filename+'!!!');
finally
target.Free;
end;
finally
source.Free;
end;
filename:string;//目标库文件名
source,target: TFileStream;
begin
source:=TFileStream.Create('源库文件名',fmOpenRead );//支持路径、扩展名;
try
target:=TFileStream.Create(filename,fmOpenWrite or fmCreate);
try
if target.CopyFrom(source,source.Size)=source.Size then
ShowMessage('成功备份到'+filename+'!!!');
finally
target.Free;
end;
finally
source.Free;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
copyfile(pchar(edit1.text),pchar(edit2.text),false);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.Execute then
edit1.Text:=opendialog1.FileName;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
if savedialog1.Execute then
edit2.Text:=savedialog1.FileName;
end;end.
edit2.text:=copy(edit1.text,1,length(edit1.text));
锁定文件关闭,并执行复制过程呀!。
edit1.text:=opendialog1.filename;
edit2.text:=savedialog1.filename;
copyfile(pchar(edit1.text),pchar(edit2.text),false);
文件,我这也遇到过这问题,先将所有的连接断开。