Inheritance and teaching old dogs new tricks...

G

Guest

I guess there is someting that I am really missing about Inheritance. I
really thought that this was going to be easy, but ....
I am converting on old app. and the users expect certain behavior. One of
these things is for the focus to move when the enter key is pressed. I have
a number of forms, so I thought I would generate a base form for all my data
entry forms to inherit from. So the first thing I put in the base form is a
Key_Down handler with the following code:
If e.KeyCode = Keys.Enter Then
If e.Shift Then
SendKeys.Send("+{TAB}")
Else
SendKeys.Send("{TAB}")
End If
e.SuppressKeyPress = True
Exit Sub
End If
Ok so far... the derived forms worked as I had expected. Now, sometimes I
want to turn this behavior off, like when I am in a multi-line textbox.
So I figured to add a protected Property to the base class as follows:

Private _CvtEnter As Boolean = False
Protected Property CvtEnter() As Boolean
Get
Return _CvtEnter
End Get
Set(ByVal value As Boolean)
_CvtEnter = value
Debug.Print("CvtEnter changed to {0}", _CvtEnter.ToString)
<=added
End Set
End Property
and surround the KeyDown code with an
If CvtEnter Then
.....
For debuging I also added this as the first line in the Key Press event.
Debug.Print("KeyDown: CvtEnter is {0}.", CvtEnter.ToString)

In the Derived forms Load event I put
CvtEnter = True
I run the app.. I see the value changed to True. I press the enter key and I
get
KeyDown: CvtEnter is False.
I don't get it! So the base class acts like it has its own 'copy' of
_CvtEnter that I can't change from the derived class. Please someone,
explain this to this old dog....
 
G

Guest

Well, I have no idea what is going on here, but the code now works! The
baseform is in the same project as the derived form and changes I made to the
base form (like debug.print statements) were immediatly reflected. But it
seems I had to compile the project in order to get it to work. I might
understand if the baseform was in a different project.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top