This one took weeks to resolve
- From: JB <JB@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 21 Sep 2008 10:08:00 -0700
While working on a project, I decided that a certain collection of forms
would be better designed as deriving from a base class form. I created a new
form and then moved common code from the collection of forms along with a few
of the common controls. I then inherited the original forms from the new
base class. These derived forms supported events and to cloud the issue a
bit, each had static members for required timers and the base class contained
a thread member. I built the project and everything worked as expected. OK
this is done. I then went to work on another section of the project and
when doing build a day or two later I started getting some obviously
nonsensical complier error messages concerning one or more of the derived
classes discussed above, this without even having the files open. The exact
errors changed from time to time but common ones would insist that a control
didn't exist when the error was pointing to the very line that created the
control in the Windows generated code. Another favorite was insisting that
InitializeComponent couldn't be accessed because it is private. By fiddling
around I discovered that if I cut any line out of the file and pasted it back
in exactly as before, the errrors when away and I was ok again for a few
builds. I should also point out that the forms always worked correctly.
Eventually it was getting to be enough of a time waster that I needed to
resolve the problem. These derived classes where the only place in a project
of well over 100 forms where the odd behavior occured. I couldn't see
offhand what was different about these particular derived classes so I
started commenting out code and seeing if things started working. In the
meantime, I had noticed that a surefire way to trigger the errors was to add
a new unrelated form to the project. Add the form, do a build and bingo,
errors. To make it even more weird, if I just deleted the new form, the
errors when away.
Enough of the background. The answer is that when I created the base class,
I moved some controls from the soon to be derived classes but in one case, I
left the event handlers in the derived classes.
Class MyBase
Inherites Mycommonbase
' this class has a btn control
End Class
Class derived
Inherites MyBase
' this is what causes the errors.
' It is tricky because it works correcly and among all the many errors
' reported by the compiler, this was never mentioned
Private sub Btn_Click(...) Handles btn.click
....
end sub
End Class
What I should have done was
Class MyBase
...
Protected Overridable Sub Btn_Click(.........) Handles ...
End Sub
end class
Class Myderived ..
Protected Overrides Sub Btn_Click( ......)
End Sub
End Class
I probably would not have made this error if I had first created the base
class and then the derived class in the usual manner but because I did it the
opposite order, I just left the btn event handlers as they were which turned
out not to be a great idea.
--
JB
.
- Prev by Date: Re: Deploying a vb.net app on a network drive - Help Needed
- Next by Date: How to wake up an asynchroneous process ?
- Previous by thread: Prevent User from moving *ONE*, not all, DATAGRIDVIEW COLUMNS???
- Next by thread: How to wake up an asynchroneous process ?
- Index(es):
Relevant Pages
|