Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posting Guidelines

 

Avatar by Lebb

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...