清帮我看看?为什么有时可以有时不可以?(50分)

  • 主题发起人 主题发起人 xxxyyyuuu
  • 开始时间 开始时间
X

xxxyyyuuu

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我想拷贝一个文件是写的,但不知为什么有时可以有时不可以?不行的时候提示:无法读取源文件或磁盘<br>TSaveDialog *savedlg=new TSaveDialog(this);<br>&nbsp; &nbsp; savedlg-&gt;Filter = "数据文件(*.mdb)|*.mdb";<br>&nbsp; &nbsp; savedlg-&gt;DefaultExt="mdb";<br> savedlg-&gt;FilterIndex = 0;<br>&nbsp; &nbsp; savedlg-&gt;Title="备份文件到";<br><br>&nbsp; &nbsp; TSHFileOpStruct fos;<br>&nbsp; &nbsp; char *buf1=new char[256];<br>&nbsp; &nbsp; char *buf2=new char[256];<br>&nbsp; &nbsp; AnsiString Str1,Str2;<br>&nbsp; &nbsp; Str1= edit_db_target-&gt;Text;<br>&nbsp; &nbsp; if (savedlg-&gt;Execute())<br>&nbsp; &nbsp; if (savedlg-&gt;FileName!="")<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; Str2=savedlg-&gt;FileName;<br>&nbsp; &nbsp; &nbsp; &nbsp; StrPCopy(buf1,Str1);<br>&nbsp; &nbsp; &nbsp; &nbsp; StrPCopy(buf2,Str2);<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.hwnd=Application-&gt;MainForm-&gt;Handle;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.wFunc=FO_COPY;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.pFrom=buf1;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.pTo=buf2;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.fFlags= FOF_SIMPLEPROGRESS;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.fAnyOperationsAborted=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.hNameMappings=NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; fos.lpszProgressTitle="正在备份文件...";<br>&nbsp; &nbsp; &nbsp; &nbsp; SHFileOperation(&amp;fos);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; delete savedlg;<br>&nbsp; &nbsp; delete []buf1;<br>&nbsp; &nbsp; delete []buf2;
 
改了一下,添加SaveDialog,不动态建,可以了!?<br>不知为何?
 
注意buf1,buf2必须至少比Str1,Str2的长度大2,因为他们必须用2个0结束字符串<br>StrPCopy(buf1,Str1);<br>buf1[Str1.Length()+1]=0;<br>StrPCopy(buf2,Str2);<br>buf2[Str2.Length()+1]=0;
 
接受答案了.
 
后退
顶部