void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
if(Trim(Form1->Edit1->Text)=="")
{ShowMessage("请输入查询内容!");
Abort();
}
bool upca;
if(Form1->CheckBox1->Checked) upca=0; else upca=1; /*是否区分大小写*/
int iFileHandle;
int iFileLength;
int iBytesRead;
char *pszBuffer;
AnsiString FindTxt=Form1->Edit1->Text;
short FindLength=FindTxt.Length();
char *FindChar=FindTxt.c_str();
unsigned short file_c;
file_c=Form1->FileListBox1->Items->Count;
Form1->RichEdit1->Lines->Clear();
for(unsigned short i=0;i
{Form1->FileListBox1->ItemIndex=i;
iFileHandle = FileOpen(Form1->FileListBox1->FileName, fmOpenRead);
iFileLength = FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
pszBuffer = new char[iFileLength+1];
iBytesRead = FileRead(iFileHandle, pszBuffer, iFileLength);
FileClose(iFileHandle);
Form1->RichEdit1->Lines->Append("*********正在查找:"+Form1->FileListBox1->FileName+" 共:"+IntToStr(iBytesRead)+"字节*********");
for(int cur=0;cur {if((!upca && pszBuffer[cur]==FindChar[0]) || (upca && UpCase(pszBuffer[cur])==UpCase(FindChar[0])))
{char rec='T';
for(int ft=1;ft {if((!upca && pszBuffer[cur+ft]!=FindChar[ft]) || (upca && UpCase(pszBuffer[cur+ft])!=UpCase(FindChar[ft])))
{rec='F';
break;
}
}
if(rec=='T')
{for(int TBegin=0;TBeginCSpinEdit2->Value*2 && cur>0;cur--)
{if(pszBuffer[cur]=='\n' || pszBuffer[cur]=='\r')
TBegin++;
}
if(cur>0 && cur
AnsiString OutTxt="";
for(int tout=0;tout< (Form1->CSpinEdit1->Value+Form1->CSpinEdit2->Value)*2 && cur {OutTxt=OutTxt+pszBuffer[cur];
if(pszBuffer[cur]=='\n' || pszBuffer[cur]=='\r')
tout++;
}
Form1->RichEdit1->Lines->Append(OutTxt);
Form1->RichEdit1->Lines->Append("*-*-*-*-*-*-*"+Form1->FileListBox1->FileName+"*-*-*-*-*-*-*-*");
}
}
}
delete [] pszBuffer;
}
Form1->RichEdit1->Lines->Append("****查找结束****");
/*delete [] FindChar;*/
阅读(1014) | 评论(0) | 转发(0) |