 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Oren Halvani Guest
|
Posted: Thu Sep 14, 2006 5:51 am Post subject: *ONLY* for Remy... |
|
|
Here you go Remy,
when i use the commented out MessageBox it will work only for one file...
not for several...
Oren
/**********************************************************/
void __fastcall TfrmMainUnit::Filter(String fileName, bool editMode)
{
String Pattern;
auto_ptr<TStringList> Results(new TStringList);
int fileCount = FileBox->Items->Count, LineCounter = 0;
bool chkCaseSensitive = frmOptions->chkCaseSensitive->Checked,
chkSeparator = frmOptions->chkSeparator->Checked,
chkTrimText = frmOptions->chkTrimText->Checked,
chkHighlight = frmOptions->chkHighlight->Checked,
chkWarnMultipleFiles = frmOptions->chkWarn_MultipleFiles->Checked;
if(chkTrimText) Pattern = txtContains->Text.Trim();
else Pattern = txtContains->Text;
if(editMode)
{
LineCounter += FilterResult(fileName, Pattern, chkCaseSensitive, Results.get());
}
else
{
if(FileBox->SelCount < 2) LineCounter += FilterResult(fileName, Pattern, chkCaseSensitive, Results.get());
else if(FileBox->SelCount > 1) // Wenn mehrere Dateien in der FileBox ausgewählt wurden...
{
if(chkWarnMultipleFiles) // Hinweis anzeigen...?
{
String str = IntToStr(FileBox->SelCount) + " " + msg_SeveralFiles + " " + Get_FileSize(FileBox);
MessageBox(NULL, str.c_str(), msg_SeveralFilesTitle.c_str(),
MB_OK|MB_DEFBUTTON2|MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST);
}
for(int x = 0; x < fileCount; ++x)
{
if(FileBox->Selected[x])
{
LineCounter += FilterResult(FileBox->Items->Strings[x], Pattern, chkCaseSensitive, Results.get());
}
}
}
}
if(Results->Count > 0)
{
int OldEventMask = rePreview->Perform(EM_SETEVENTMASK, 0, 0);
try
{
Screen->Cursor = crHourGlass;
rePreview->Lines->Assign(Results.get());
}
__finally
{
rePreview->Perform(EM_SETEVENTMASK, 0, OldEventMask);
Screen->Cursor = crDefault;
}
if(chkHighlight) {Highlight();} // Ergebnisse optisch hervorheben..
/******** File-Separator & Event Labels ******************************************/
int not_wanted_records,
wanted_records,
sel_items = 0,
lines = FileBox->Items->Count;
if(chkSeparator)
{
for(int x = 0; x < lines; ++x) if(FileBox->Selected[x]) sel_items++;
not_wanted_records = LineCounter - Results->Count + sel_items;
wanted_records = rePreview->Lines->Count - sel_items;
}
else
{
not_wanted_records = LineCounter - Results->Count;
wanted_records = rePreview->Lines->Count;
}
lblFiltered_Records->Caption = Thousand(not_wanted_records);
lblWanted_Records->Caption = Thousand(wanted_records);
/******** File-Separator & Event Labels ******************************************/
}
else
{
//Application->MessageBox(msg_NotFound.c_str(), msg_NotFoundTitle.c_str(), MB_OK | MB_ICONERROR);
lblFiltered_Records->Caption = lbl_FilteredRecord;
}
} |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Sep 14, 2006 6:32 am Post subject: Re: *ONLY* for Remy... |
|
|
"Oren Halvani" <Spam (AT) halvani (DOT) de> wrote in message
news:4508a7b7 (AT) newsgroups (DOT) borland.com...
| Quote: | when i use the commented out MessageBox it will work only
for one file...not for several...
|
You did not show the code that is calling Filter(), and you did not say what
is actually failing and under what conditions. All you have done is shown a
Filter() function, but you did not show what is actually calling Filter(),
and with what parameters. It would also be helpful if you would explain
what the code is trying to do, what results you are expecting from it, and
what results you are actually getting from it instead.
Gambit |
|
| Back to top |
|
 |
Oren Halvani Guest
|
Posted: Thu Sep 14, 2006 6:42 am Post subject: Re: *ONLY* for Remy... |
|
|
1.) void __fastcall TfrmMainUnit::Filter(String fileName, bool editMode)
this function is taking the specific file as the 1st parameter and a bool value
that should check if a simple RichEdit->Text should be filtered out instead
of all the given files...
2.) the following FilterResult() function is making the "real" work, if
a given file include the given pattern it should be added into a TStrings
object via Results->Add( ) which than will be the content of theRichEdit->Text...
FilterResult( ) returns the count of those lines which include the specific
pattern and where added via Results->Add( )
what i need is to check if any of the given files is including at least one
line which contains the pattern, otherwise it should show a MessageBox
that NO ONE of the given files is including the pattern...
thats all...
what i get right now:
ONLY a MessageBox() if the pattern couldn't be found in a RichEdit->Text
instead of if it couldn't be found in the given files....
Oren
/*******************************************************/
int __fastcall TfrmMainUnit::FilterResult(const AnsiString &FileName,
const AnsiString &Pattern,
bool CaseSensitive,
TStrings *Results)
{
std::auto_ptr<TStringList> Original(new TStringList);
Original->LoadFromFile(FileName);
bool chkLineBegin = frmFilterOptions->chkText_LineBegin->Checked,
chkLineEnd = frmFilterOptions->chkText_LineEnd->Checked,
chkTextPos = frmFilterOptions->chkText_Pos->Checked,
chkHowMuch = frmFilterOptions->chkHowMuch->Checked,
chkSeparator = frmOptions->chkSeparator->Checked;
int BoxSelect = frmFilterOptions->boxDelOptions->ItemIndex,
HowMuch = StrToInt(frmFilterOptions->txtHowMuch->Text),
txtPos = StrToInt(frmFilterOptions->txtPos->Text);
String file_sep = frmOptions->txtSeperator->Text + "( " + FileName + " )" + frmOptions->txtSeperator->Text;
FCancelled = false; ::GetAsyncKeyState(VK_ESCAPE);
/************************************************/
if(chkSeparator) {Results->Add(file_sep);}
/************************************************/
Results->BeginUpdate();
try
{
for(int x = 0; x < Original->Count; ++x)
{
if(IsCancelled()) break; // Loop verlassen..
AnsiString line = Original->Strings[x];
int diff = line.Length() - Pattern.Length(),
idx;
if(CaseSensitive) idx = line.Pos(Pattern);
else idx = CaseInsensitivePos(line, Pattern);
/**** Auswahl: Filtern oder behalten ?? ****************************************/
if(BoxSelect == 0)
{
if(chkLineBegin) {if(idx == 1) Results->Add(line);}
if(chkLineEnd) {if(idx == (diff + 1)) Results->Add(line);}
if(chkTextPos) {if(idx == txtPos) Results->Add(line);}
if(chkHowMuch)
{
if(HowMuch > 1)
{
if(HowMany(line, Pattern, HowMuch) == HowMuch) Results->Add(line);
}
}
}
if(BoxSelect == 1)
{
if(chkLineBegin) {if(idx != 1) Results->Add(line);}
if(chkLineEnd) {if(idx != (diff + 1)) Results->Add(line);}
if(chkTextPos) {if(idx != txtPos) Results->Add(line);}
if(chkHowMuch)
{
if(HowMuch > 1)
{
if(HowMany(line, Pattern, HowMuch) != HowMuch) Results->Add(line);
}
}
}
if(!chkLineBegin && !chkLineEnd && !chkTextPos && !chkHowMuch) {if(idx != 0) Results->Add(line);}
} // END OF FOR ( ) LOOP.....
}
__finally
{
Results->EndUpdate();
}
return Original->Count;
} |
|
| Back to top |
|
 |
Oren Halvani Guest
|
Posted: Fri Sep 15, 2006 6:23 am Post subject: Re: *ONLY* for Remy... |
|
|
Problem solved....
thanks anyway  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|