|
rose196 wrote: Can you tell me how to find more than one time occurence word
Maybe RichTextBox::Find()[^]
At least one of the overloads takes a starting point index. You can repeatedly search from the end of
previous successful Find calls.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I need to change the colour of particular word in a file.
So that i store that word in array then find the length of the file.
I Put it in for loop. if the word is found then it will change the color.
Now my problem is if the word is occur more than one time the color not changed.
can you tell me what is the mistake ?
I used Mc++, my code is as follows.
array<String^>^ keyword = gcnew array<String^>{"int", "void", "float","double","longint"};
int len = keyword->Length;
int Lines = this->srcTextBox->Lines->Length;
for(int i=0;i<Lines;i++)
{
for(int j=0;j<len;j++)
{
String ^searchStr = this->srcTextBox->Lines[i];
String ^key = keyword[j];
bool found;
found = searchStr->Contains(key);
if(found)
{
if(this->srcTextBox->Find(key,RichTextBoxFinds::MatchCase))
{
this->srcTextBox->SelectionColor = Color::Blue;
}
}
}
}
Thanks
|
|
|
|
|
rose196 wrote: if(this->srcTextBox->Find(key,RichTextBoxFinds::MatchCase))
You should be checking if Find() returns >= 0
I'm not a big forms user, but I'm pretty sure you need to select the text if you want to see
a color change.
Maybe something like this...
int FoundTextIndex = this->srcTextBox->Find(key,RichTextBoxFinds::MatchCase);
if(FoundTextIndex >= 0)
{
this->srcTextBox->Select(FoundTextIndex, key->Length);
this->srcTextBox->SelectionColor = Color::Blue;
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for reply
I tried with your code. But I didn't get the result.
I have one doubt.
Using find() same word occurence in more than line search is passible.
Thanks.
modified on Thursday, April 3, 2008 5:26 AM
|
|
|
|
|
I don't understand why you are searching both the "Lines" strings and the RichTextBox text.
If you need multiple searches in the Lines strings, use the String::IndexOf() method instead of Contains().
rose196 wrote: Using find() same word occurence in more than line search is passible.
I don't know what you mean. The Find() methods search all the text in the textbox. You can
use it to find all occurrences of a string in the textbox text, but you need to loop.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for your replay.
Now i'll explain what i am doing.
I read the file and display that file in the richtextbox. Now what i want means file displayed in the richtextbox has certain keywords. I want to display that keyword in color.
Ok,
For this i Wrote the code as i said above. Now my problem is some keywords is presented in multiple line, that keyword color is not changed while i am executing.
forexample.
if keyword "int" is present in the 1st line and 4th line. the 1st line "int" keyword color is changed 4thline "int" keyword color is not changed.
I dont know why?
Now can you give idea.
Thanks.
|
|
|
|
|
Then there's no reason to search the individual lines.
For each keyword you need to search the entire text. That means using the Find() method that takes
an index of a starting point. Start at index 0. When you find a keyword, hilight it. Do the next search from
the end of the previous found keyword. Repeat until you reach the end of the text (Find() fails).
In your current code, you're only using methods to find ONE keyword. What I'm trying to convey to you is, you'll need to
write proper code to do what you want. Here's an example (untested):
array<String^>^ keyword = gcnew array<String^>{"int", "void", "float", "double", "longint"};
<font color="Green">
for(int i = 0; i < keyword->Length; i++)
{
String ^key = keyword[i];
<font color="Green">
int TextIndex = srcTextBox->Find(key, 0, RichTextBoxFinds::MatchCase);
<font color="Green">
while (TextIndex >= 0)
{
srcTextBox->Select(TextIndex, key->Length);
srcTextBox->SelectionColor = Color::Blue;
TextIndex += key->Length;
if (TextIndex >= srcTextBox->TextLength)
break;
<font color="Green">
TextIndex = srcTextBox->Find(key, TextIndex, RichTextBoxFinds::MatchCase);
}
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark
Thank you very much . Your code helps me alot
|
|
|
|
|
Hi everyone,
currently I am writing a wrapper for some native library which offers a hand full of callbacks.
I wrote some .net events which are called when these callbacks are triggered.
So far no problems, but I cannot work with the result strings etc. from the application that uses my assembly, because the events are still called from a thread different from the UI thread.
Is there any chance to call the events through some dispatcher within my mixed assembly? I would like to avoid that the user has to write some code on his own to dispatch the events.
Since that is the expected event behavior, is it possible that I am doing something wrong at all?
Sincerly,
Roland
|
|
|
|
|
Don Rolando wrote: from the application that uses my assembly, because the events are still called from a thread different from the UI thread.
Not sure I understand you correctly but it sounds like you are saying that your application code is registering an event handler for an event published in a class in the library. The library fires the event from a worker thread and therefore the application codes event handler is executing on the worker thread.
If that is correct I would point out first that from a library design stand point, that doesn't seem like a good idea. The library should managed the thread communications such that the event fires on the main thread.
However a simple solution is to have your application event handler call BeginInvoke to update the UI components.
You can find much information[^] about this topic
led mike
|
|
|
|
|
You understood it correctly; but the bad news is that I cannot modify the design of the library which is embedded in my assembly. I have these callbacks fired from the lib-file's worker thread.
I have thought about BeginInvoke myself, but in this case I cannot hide the dispatching process from the user (or can I?), because it must be implemented in the app's event handler - so the user has to write that code himself.
I would need that dispatching process in between the callback from the worker thread in the lib file and the event handler.
|
|
|
|
|
Have a deeper insight on BeginInvoke I realized that I could also do this on the event's delegate. So more or less I could start the invocation within my assembly;
anyhow, I can't get it work in C++/CLI, because either the event is not recognized as a data member (seems to be a C++/CLI specific behavior, as I read so far) or the AsyncCallback structure will not work, grrr.
Does anyone have a short code snippet how to invoke some event in C++/CLI correctly?
|
|
|
|
|
Don Rolando wrote: Does anyone have a short code snippet how to invoke some event in C++/CLI correctly?
I never looked at the them but I bet you will find an example in the introductory CLI articles here on CodeProject. Look under the "Chapters" menu.
led mike
|
|
|
|
|
Don Rolando wrote: I cannot modify the design of the library which is embedded in my assembly. I have these callbacks fired from the lib-file's worker thread.
Don Rolando wrote: I cannot hide the dispatching process from the user (or can I?), because it must be implemented in the app's event handler - so the user has to write that code himself.
That information is very confusing. If it is your assembly, why can't you modify it?
led mike
|
|
|
|
|
The assembly is from me, right... but not the linked lib-file which generates it's own worker threads and calls the callbacks. That's kind of a black box which's architectural design I cannot modify in any way.
But I can try to start the dispatching when firing the event out of these callbacks. That's still within the assembly (but would however not beautify the general architecture),
Silly thing is that I could not find examples for BeginInvoke on delegates for C++/CLI so far... only on controls or in C#; and I read that C++/CLI is different in that case and cannot be handled the same way... but I will get it work soon, I am sure.
|
|
|
|
|
Hello all,
I'd very grateful for your help with compilation error I get after migrating from Visual Studio .NET 2003 to Visual Studio 2005.
class A is a managed class which contains pointer pPtr to unmanaged class as public member
class B is a managed class, derived from A.
In constructor of B there is an initialization of pPtr
after migrating from Visual Studio .NET 2003 to Visual Studio 2005 I get a compilation error:
cannot access a private member of class A (pPtr)
I'm using Old Syntax.
Thanks in advance,
Maya
|
|
|
|
|
mayag wrote: I'm using Old Syntax.
I don't recommend that.
As to your problem the newer C++ compilers are more standards compliant than the old ones. private is private, as in, not visible to derived classes. If you want derived classes to access the member make it protected, although this is not a normal design holding the principle of encapsulation but that is another matter.
Also Microsoft maintains a page of the breaking changes between compliers which could help you. There are also like a migration guide or something. Also here on CodeProject there exists an excellent set of articles introducing the CLI language extensions, I highly recommend those to anyone new to CLI.
led mike
|
|
|
|
|
i have a major problem with the HtmlDocument HtmlElement ... methods...
im tryn to code a browser in wich i can automaticle fill a form and submit it.
this is the form code <code>form name="loginform" method="POST" action="/login.php">
<input class="loginname" type="text" name="name" value="" style="width:8em;" maxlength="60" />
<input class="passwort" type="password" name="password" value="" style="width:8em;" maxlength="60" />
<input type="submit" name="login" value="Login" style="width:7em;" /><br /></code>
this are my attempts
<code> HtmlDocument ^doc = webBrowser1->Document;
label1->Text = doc->Title->ToString();
//HtmlElement ^feld1 = webBrowser1->Document->GetElementsByTagName("name");
//HtmlElement ^feld1 = webBrowser1->Document->Forms->GetElementsByName("loginname");
//feld1->SetAttribute("HALLO",name);
//doc->GetElementsByTagName("loginname");
HtmlElementCollection ^feld2 = webBrowser1->Document->Forms;
feld2->GetElementsByName("loginname");
//HtmlDocument ^feld2 = webBrowser1->Document->Forms->GetElementsByName("name");
//feld2->SetAttribute("Hallo",name);
//HtmlElement ^button = webBrowser1->Document->GetElementById("Login");
//button->InvokeMember;
//HtmlInputDocument ^name = doc("name",0);
//doc->HtmlDocument::Forms::get();
//doc->GetElementsByTagName("login");
//doc->Forms->GetElementsByName("login");
//doc->GetElementById("login")</code>
can anyone help me with this? i'm desperated
|
|
|
|
|
Is there some specific reason you don't just make a HTTP Post request?
led mike
|
|
|
|
|
well i like to understand this methodes. because i need them later to find links and pictures in the document
|
|
|
|
|
I assume you are working inside of DOM from the web browser object?
If so you directly interact with the elements them self, no need to try to submit the post directly as the browser object will do that for you.
System::String^ part = "XYZ";
HtmlElement^ x = WebBrowser::Document::GetElementById("PartNum");
if (x != nullptr)
{
x->SetAttribute("value", part);
x = WebBrowser::Document::GetElementById("Submit");
if (x != nullptr)
{
x->InvokeMember("click");
}
}
|
|
|
|
|
How do I read in words from a text file one at a time? I do not want the blank space or puncuation.
The file is long.
|
|
|
|
|
While there's still data in the file
{
Read an arbitrary amount of the file
Loop through the data read, parsing out the words
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
So like this?
while (!eof())<br />
while (fin != '\n')<br />
{<br />
fin >> words[i];<br />
i++;<br />
}<br />
}
|
|
|
|
|
Something like that should work, although it looks like you're parsing lines, not words.
Many stream classes have built-in support for reading lines of text, but I know of none that
parse words.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|