|
testUserList is being declared in the full programm when a new userlist is being created in another function.
But in the code I need to check a UserList has already been created thus i use if (testUserList != null to check if it really exists.
But my redefined function doesnt like a 'null' as parameter...
|
|
|
|
|
From past experience, overloading == and != on a class is generally not a good idea because of the possiblity of it being null.
It works great for structs, but that can bring other problems!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Do you have a better idea to check the equality of an own List<>?
Shall I create a completely new function like ownEqualityCheck(UserList userlist...); ?
|
|
|
|
|
I've just had another look at this. It seems that by converting your class instances to objects, you can do a null check. e.g.
public class Test
{
private int internalValue;
public Test(int value)
{
internalValue = value;
}
public static bool operator ==(Test test1, Test test2)
{
object o1 = test1;
object o2 = test2;
if (o1 == null || o2 == null)
return (o1 == null && o2 == null);
return test1.internalValue == test2.internalValue;
}
public static bool operator !=(Test test1, Test test2)
{
return !(test1 == test2);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
thank you very much for your hint!
I implemented it and it just works fine!
Regards,
Chris
|
|
|
|
|
Thsi may be silliy, but your operator overload code doesn't do any checking to see if one of the object passed in is null or not before trying to use it. You should be check to see if you actually have an object, handle the case where the object is null , then check to see if it is a valid object type to compare against, ...
|
|
|
|
|
So your advice is to use overloading the == Operator but with additional checks like:
public static bool operator ==(UserList userlist1, UserList userlist2)
{
if (userlist1 == null) return false;
....
}
But by doing so i repeatedly call the ==-Operator recursivly. Is this ok? I believe i get the NullPointerExcception as well.
--> ok I tested it and I get a StackOverflowException. Thats sort of what I Expected.
modified on Friday, July 10, 2009 5:53 AM
|
|
|
|
|
How can I load an XML Document to an ObservableCollection class that preserves the XML tree structure?
My xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://none.none.none/webservices">
<TREENODES xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<TREENODE code="1" text="None" >
<TREENODE code="2" text="America" >
<TREENODE code="16128" text="AUTOS">
<TREENODE code="ATO" text="ATO" />
<TREENODE code="ATO" text="ATO" />
</TREENODE>
</TREENODE>
</TREENODE>
<TREENODE code="11" text="None" >
<TREENODE code="21" text="America" >
<TREENODE code="3" text="AUTOS">
<TREENODE code="ATO44" text="ATO5" />
</TREENODE>
</TREENODE>
</TREENODE>
</TREENODES>
</string>
|
|
|
|
|
Depends on what you're loading it for. What is the consumer of the object?
You can make something like:
public class TreeNode
{
public string Code { get; set; }
public string Text { get; set; }
public List<TreeNode> Children { get; set }
public TreeNode()
{
Children = new List<TreeNode>();
}
}
In both WPF and Silverlight you could databind with a hierarchal template.
Again, it all depends on how/what/why you are using it.
You can populate the tree using LINQ to XML.
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
So what would be the LINQ?
Thanks in Advance
|
|
|
|
|
Also this class it seems that will create a simple list. Not a tree like the XML.
|
|
|
|
|
It will create a hierarchal object graph. Something like this would populate it:
public TreeNode Populate(XDocument doc)
{
var retVal = (from treeNode in doc.Descendants("TreeNode")
select new TreeNode()
{
Code = treeNode.Attribute("Code").Value,
Text = treeNode.Attribute("Text").Value
}).SingleOrDefault();
retVal.Children = _Recurse((from treeNode in doc.Descendants("TreeNode")
select treeNode).SingleOrDefault());
return retVal;
}
private static List<TreeNode> _Recurse(XContainer root)
{
List<TreeNode> retVal = new List<TreeNode>();
var children = from child in root.Descendants("TreeNode") select child;
foreach(var child in children)
{
TreeNode node = new TreeNode
{
Code = child.Attribute("Code").Value,
Text = child.Attribute("Text").Value,
Children = _Recurse(child)
};
retVal.Add(node);
}
return retVal;
}
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
Have you seen the Linq exception
"Sequence contains more than one element"? It comes from Populate.
|
|
|
|
|
it was the FirstOrDefault not SingleOrDefault.
Will this work if I change the class from List to ObservableCollection?
Thanks a bunch.
|
|
|
|
|
Hi All,
I am developing a Windows Service application.
It connects the SQL server for data.It uses the Integrated security = true for the connection string.
My serivice is running fine while the Service and SQL running in same NT domain.
It throws an error for (cross domain) while service in Domain1 and SQL server in Domain2.
Is there any way to resolve the issue without changing the Integrated security and passing the User name and password. Does it make sense?.
Thanks in advance.
Regards,
Arafath.
|
|
|
|
|
I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine.
Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?
|
|
|
|
|
Hi,
Threads (all kinds of them, including ThreadPool threads, and BackgroundWorkers) other than the thread that created a Control (BTW: a Form is also a Control), should not access that Control, except for the very few members explicitly allowed, including InvokeRequired and Invoke.
Before .NET 2.0 the app may behave badly, the GUI may freeze, anything can go wrong if you violate the rule.
Since 2.0 you get an InvalidOperationException by default; you can disable that by setting Control.CheckForIllegalCrossThreadCalls false, but that is a very bad idea, and it brings you back in the previous situation.
Since most if not all Controls are somehow related (they are on a Form, one Form owns another Form, etc), the natural consequence is all Controls get created and accessed exclusively by a single thread, typically your initial or main thread, often also called the "GUI thread".
There are lots of examples on InvokeRequired/Invoke available everywhere;
a rather advanced article on the subject is here.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
OK so I found something. Though I set the text values in a thread safe manner apparently I don't set the panel's visible property in a thread safe manner. Any suggestions on how to do that? Please don't say a timer, because I have had such bad luck with the form timers in this program. I just can't get them to tick, but that is another issue.
Edited to add:
Weird I didn't see that last reply until after I posted this.
I will check out the link. Thanks
|
|
|
|
|
OKay I got it.
static void SetVisible(Control ctrl, bool visible)
{
if (ctrl.InvokeRequired)
{
object[] params_list = new object[] { ctrl, visible };
ctrl.Invoke(new SetVisibleDelegate(SetVisible), params_list);
}
else
{
ctrl.Visible = visible;
}
}
|
|
|
|
|
How to convert html to image using webbrowser?
Write a code, please.
|
|
|
|
|
About all you can do, is take a screenshot.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
It is probably better that you write your own code to be fair.
|
|
|
|
|
Set DocumentText to the HTML code, then draw it to a Bitmap. If you have the web URL the source code came from - even better. Navigate to that, then draw to a Bitmap as before
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
|
Hello Everyone-
I am looking at making an application that will detect the square footage of a piece of wood that is placed on a table. I am thinking that the table will have a bright orange color, so the dark wood placed on it would provide a lot of contrast. I will use a camera to take a picture of the table (the table lets say is 6 FT by 6 FT) and analyze the image to figure out how big the piece of wood is that has been placed on this table.
I am wondering if anyone can point me in the right direction here code wise (like search terms, etc). I've so far made it to Blob Analysis and have been reading about that. Any help or pointers into exactly what I need to learn to make this possible would be appreciated immensely!
Thank you!
EDIT: I also am wondering if it would be possible to somehow equate each pixel with a real life measurement, such as 1mm, and if it was possible to somehow calculate the pixels that were not orange, and come up with a measurement that way (Because some times the pieces of wood are not going to be square or rectangular ... but I figured I would get the sq/rect down first because I just figured that would be the easiest). I'm in the middle of reading an awesome multi-part article on this site about it, but just trying to figure out which way to go next.
Thanks much!
modified on Thursday, July 9, 2009 9:42 AM
|
|
|
|