mookie Posted February 18, 2005 Posted February 18, 2005 Im trying to add a property to my richtextbox control to determine whether it has been modified since being opened or saved. if i use this, i get a stack overflow. I dont know what it is that im doing wrong for this. I also need to access and set the property from both the form and the mdi parent. Public Property changed() As Boolean Get Return changed End Get Set(ByVal Value As Boolean) changed = Value End Set End Property Quote
Mike_R Posted February 18, 2005 Posted February 18, 2005 That code is essentially calling itself... It's not as obvious when looking at it, but it's a lot like a function that looks like this: Function MyFunction() As Boolean Return MyFunction End Function The result is infinite recursion, as each call generates another call to itself... The stack simply builds up until it eventually overflows. :( But the correction is simple: Private _changed As Boolean = False Public Property changed() As Boolean Get Return _changed End Get Set(ByVal Value As Boolean) _changed = Value End Set End Property The idea is that a Property is really just a wrapper for a field. You create a Private Boolean and call it '_changed' and then your Public Property then Gets or Sets the '_changed' value. :), Mike Quote Posting Guidelines Avatar by Lebb
mookie Posted February 18, 2005 Author Posted February 18, 2005 That code is essentially calling itself... It's not as obvious when looking at it, but it's a lot like a function that looks like this: Function MyFunction() As Boolean Return MyFunction End Function The result is infinite recursion, as each call generates another call to itself... The stack simply builds up until it eventually overflows. :( But the correction is simple: Private _changed As Boolean = False Public Property changed() As Boolean Get Return _changed End Get Set(ByVal Value As Boolean) _changed = Value End Set End Property The idea is that a Property is really just a wrapper for a field. You create a Private Boolean and call it '_changed' and then your Public Property then Gets or Sets the '_changed' value. :), Mike Thanks. I kinda realized this a couple minutes ago but was still questioning my self due to i didnt really think that i would have to do something to the effect of _changed = true changed = _changed thanks though Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.