请帮忙看看,下面的代码有何不对啊?(47分)

  • 主题发起人 主题发起人 ynduanlian
  • 开始时间 开始时间
Y

ynduanlian

Unregistered / Unconfirmed
GUEST, unregistred user!
我希望遍历e盘下的所有目录文件,把它显示在MEMO1中,下面的代码是根据DELPHI改写的,编译时没问题,但一运行总报错:
TForm1 *Form1;
int intTotalFileNumbers;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
intTotalFileNumbers=0;
}
//---------------------------------------------------------------------------
//返回0,是文件;1子目录;2上级或本目录
int TForm1::CurrentIsValidDir(TSearchRec* SearchRec){
if ((SearchRec->Attr!=16) &&
(SearchRec->Name!=".") &&
(SearchRec->Name!=".."))
return 0;
if ((SearchRec->Attr==16) &&
(SearchRec->Name!=".") &&
(SearchRec->Name!=".."))
return 1;
return 2;
}

void TForm1::RecurSearchFile(String CurrentDir,String SearchFileType,TStrings *SearchResult,int Number){
TSearchRec* SearchRec;
TStringList* SubDir;
int i;
if (FindFirst(CurrentDir+SearchFileType, faAnyFile, *SearchRec)==0){
do
{
if (CurrentIsValidDir(SearchRec)==0){
Number++;
SearchResult->Add(CurrentDir+SearchRec->Name);
}
Application->ProcessMessages();
}while (FindNext(*SearchRec)!= 0);
}
FindClose(* SearchRec);
SubDir=new TStringList();
if (FindFirst(CurrentDir+"*.*", faDirectory, *SearchRec)==0){
do
{
if (CurrentIsValidDir(SearchRec)==1)
SubDir->Add(SearchRec->Name);
Application->ProcessMessages() ;
}while(FindNext(* SearchRec)!=0);
}
FindClose(* SearchRec);
for (i=0;i<=SubDir->Count-1;i++)
RecurSearchFile(CurrentDir+SubDir->Strings+"//",SearchFileType,SearchResult,Number);
// delete SubDir;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Clear();
intTotalFileNumbers=0;
RecurSearchFile("e://","*.*",Memo1->Lines, intTotalFileNumbers);
}
//---------------------------------------------------------------------------
 
粗看一下,你好像没给SearchRec分配内存,它还是未定义指针。
 
接受答案了.
 
后退
顶部