-
May 28th, 2011, 08:37 AM
#1
List of errors when debug the application - please help!
hi guys,
I have a problem with the source code, when I tried to debug the application, I get the list of errors.
The errors is:
'System::Collections::Generic::List<T>::ToArray': function call missing argument list; use '&System::Collections::Generic::List<T>::ToArray' to create a pointer to member
error C2955: 'System::Predicate' : use of class generic requires generic argument list
error C2276: '&' : illegal operation on bound member function expression
error C3350: 'System::Predicate' : a delegate constructor expects 2 argument(s)
Code:
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
Random ^r = gcnew Random();
List<ListViewItem^> ^items = gcnew List<ListViewItem^>();
for each (Match ^x1 in matches1)
{
array<String^> ^StrArr1 = x1->Value->ToString()->Split();
items->Add(gcnew ListViewItem(gcnew array<String^> {x1->Value->ToString()->Replace("<p id='channel_name'>", "")->Replace("</p>", "")}));
}
ListView1->Items->AddRange(items->ToArray);
}
private: System::Void TextBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
Random ^r = gcnew Random();
List<ListViewItem^> ^items = gcnew List<ListViewItem^>();
array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray, gcnew System::Predicate(&isMatch));
ListView1->Items->Clear();
ListView1->Items->AddRange(filteredItems);
}
If you know how to fix the errors, I would be grateful.
Thanks,
Mark
-
May 28th, 2011, 11:23 AM
#2
Re: List of errors when debug the application - please help!
Originally Posted by mark103
I have a problem with the source code, when I tried to debug the application, I get the list of errors.
I somehow doubt that you get those errors only when trying to debug. These are compiler errors that I would expect to be thrown during a release build as well.
BTW, it would have been helpful if you had indicated on which code lines you got the errors.
'System::Collections::Generic::List<T>::ToArray': function call missing argument list; use '&System::Collections::Generic::List<T>::ToArray' to create a pointer to member
List<T>::ToArray() is a function, so yo need an empty pair of braces when you want to call it:
Code:
ListView1->Items->AddRange(items->ToArray());
That's all the error message effectively means, though I must admit it's telling you that in a pretty cryptic way...
error C2955: 'System::Predicate' : use of class generic requires generic argument list
error C2276: '&' : illegal operation on bound member function expression
error C3350: 'System::Predicate' : a delegate constructor expects 2 argument(s)
These are all for the same code line, aren't they?
The Predicate<T> delegate constructor requires you to explicitly specify the argument type that's passed to the predicate. And if the delegate "points" to a non-static member function of a class it indeed needs two parameters: The object handle to call the function on (in many cases this is this but not always) and a pointer-to-member to the function (which by its nature does not contain the object reference, thus the requirement for the first parameter).
Code:
array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray(), gcnew System::Predicate<ListViewItem^>(this, &isMatch));
I can only guess that isMatch() is a member of the same form class but I think it's likely, hence the this as the first parameter to the delegate constructor.
I think the C2276 is a consequential error and pretty misleading. It should go away once you correct the other flaws.
A bit puzzling is the fact that delegate constructors make do with a single parameter when used for a static member or free function.
BTW...
Code:
array<String^> ^StrArr1 = x1->Value->ToString()->Split();
The parameterless version of String::Split() is apparently undocumented on MSDN but it obviously is there and works. Where did you find it and by exactly which delimiters does it split?
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
May 28th, 2011, 05:16 PM
#3
Re: List of errors when debug the application - please help!
Thanks Eri523, I have replaced the code you have posted, but I am getting some errrors when I ran the debug.
error C2276: '&' : illegal operation on bound member function expression
error C3350: 'System::Predicate<T>' : a delegate constructor expects 2 argument(s)
The error are jumping on this line:
Code:
array<ListViewItem^> ^filteredItems = Array::FindAll(items->ToArray(), gcnew System::Predicate<ListViewItem^>(this, &isMatch));
do you know how to fix the errors that I am getting?
-
May 28th, 2011, 06:28 PM
#4
Re: List of errors when debug the application - please help!
Last edited by Eri523; May 28th, 2011 at 06:54 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
May 30th, 2011, 07:55 AM
#5
Re: List of errors when debug the application - please help!
Thanks Eri523, I can see the problem has got rid of the errors, but I can't fill the data that I have extact from my website.
Code:
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show("timer starts now");
timer1->Enabled = false;
Form2 ^form7 = gcnew Form2();
try
{
//Address of URL
String ^URL = "http://www.mysite.com/Login.php?user=" + form2->ComboBox1->Text + "&pass=" + form2->TextBox1->Text;
HttpWebRequest ^request = safe_cast<HttpWebRequest^>(WebRequest::Create(URL));
HttpWebResponse ^response = safe_cast<HttpWebResponse^>(request->GetResponse());
StreamReader ^reader = gcnew StreamReader(response->GetResponseStream());
String ^str = reader->ReadToEnd();
String ^pattern1 = "(<p id='myid1'>(.*?)</p>)";
MatchCollection ^matches1 = Regex::Matches(str, pattern1);
Random ^r = gcnew Random();
List<ListViewItem^> ^items = gcnew List<ListViewItem^>();
for each (Match ^x1 in matches1)
{
array<String^> ^StrArr1 = x1->Value->ToString()->Split();
items->Add(gcnew ListViewItem(gcnew array<String^> {x1->Value->ToString()->Replace("<p id='myid1'>", "")->Replace("</p>", "")}));
}
ListView1->Items->AddRange(items->ToArray());
}
catch (Exception ^ex)
{
MessageBox::Show("the site you request is down!");
}
}
When I set the timer, the data suppose to be fill on the listview but it have filled as empty items.
Do you know why and how to fix this?
Last edited by mark103; May 30th, 2011 at 07:57 AM.
-
May 30th, 2011, 09:52 AM
#6
Re: List of errors when debug the application - please help!
Originally Posted by mark103
Do you know why and how to fix this?
Not really. I'd suggest to step through your code with the debugger and observe your data to find the spot where things begin to go wrong. Having narrowed down the bug location to that single small function makes that not much effort. The fact that you're getting empty items and not no items seems to indicate that there actually are regex matches.
What is StrArr1 intended to be used for? You assign a value to it but then never use it. (You're not using r either but that seems to be unrelated to the problem.)
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
June 1st, 2011, 05:48 PM
#7
Re: List of errors when debug the application - please help!
Okay, no worries. I think I got a different way to get this solve. Do you know how to do the autosearch for the textbox to search through the listview?
-
June 1st, 2011, 10:00 PM
#8
Re: List of errors when debug the application - please help!
I have not that much (well, to be honest, it's actually plain zero) experience with the ListView class. However, it looks like you intend to tie the selection of your ListView to a TextBox's TextCanged event. Though this certainly is possible in general it may raise some reaction time issues, based on what/how many data are stored there in the ListView. Basically I don't see an alternative to code that yourself.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|