内存问题(贴代码)~~大家进来帮忙.
偶做一个文件的选取与备份.我写了下面这个函数.
问题:
此程序正常编译与运行.
如果没有使用这个选取与备份功能,就能正常关闭.
但是,只要使用了这个功能,就会产生内存错误.(程序运行结果是对的!)
偶找不到原因.我在跟踪代码时发现:在这个执行这个函数后就出现内存错误如下:
'Access Violation at address '00499f0d in module 'project1.exe'. read of address 017c462a',process stopped.use step or run to continue.
void mend(AnsiString subverstr_1 ,AnsiString mendfilepath_1,AnsiString copypath)
{
TSearchRec sr;
int iAttributes = 0;
iAttributes |= faReadOnly;
iAttributes |= faHidden ;
iAttributes |= faSysFile;
iAttributes |= faVolumeID;
iAttributes |= faDirectory;
iAttributes |= faArchive;
iAttributes |= faAnyFile;
if (FindFirst(ExtractFilePath(Application->ExeName) + "\\*.*", iAttributes, sr) == 0)
{
AnsiString c=strcat(subverstr_1.c_str(),"QzServer.exe");
do
{
if (strcmp(sr.Name.c_str(),c.c_str())==0 )
{
AnsiString oldfile_1=strcat(mendfilepath_1.c_str(),sr.Name.c_str());
AnsiString nfile_1=strcat(copypath.c_str(), "QzServer.exe") ;
if ( CopyFile(oldfile_1.c_str(), nfile_1.c_str(),true)==true)
{
// ShowMessage("*****!") ;
}
else
{
// ShowMessage("******!")
}
}
}
while (FindNext(sr) == 0);
FindClose(sr);
}