Error in Form Constructor

S

Steve W

We are hitting a problem that we can't explain and wondered if anyone has
seen this before or can suggest how we can stop it happening :

Form 'A' inherits from System.Windows.Forms.Form
Form 'B' inherits from Form 'A'.
Form C inherits from Form B.

Form B (the one in the middle) has a TextBox component on it.

The constructor of Form 'C' attempts to assign a string value to the 'Text'
property of the TextBox. It does this after all form initialization has
taken place.

Occasionally (we haven't identified a definite pattern), when the code
assigning the 'Text' property of the TextBox executes, it falls over with an
exception 'Object variable not set to an instance of an object'.

The problem definitely lies with the assignment (i.e. does not lie with the
value being assigned). We've also tried Me.TextBox.Text = value and
MyBase.TextBox.Text = value but still the same. We've also tried assigning
values to different components (such as CheckBox.Checked = True) and the
same thing happens. The component can be read; i.e. code like
MsgBox(TextBox.Text) works fine.

We thought we had solved the problem when discovering that if the component'
s properties have anything assigned to them at design time, then this
run-time issue would occur fairly frequently (but seemingly randomly).
Ensuring nothing is assigned at design time (i.e. the 'Text' property or
'Checked' property is not assigned at design time) seemed to halt the issue
occurring. However, now it is occurring again and we can't fix it.

This does seem to be a form inheritance issue as I haven't seen it on any
forms that are just inherited from System.Windows.Forms.Form.


Thanks for any help,

Steve
 
J

Jeffrey Tan[MSFT]

Hi Steve,

Have you succeeded create out a sample project to reproduce this issue? Is
your problem resolved? Please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Steve W

Jeffrey,

Some confusion our end. One of my guys will be looking at it tomorrow.

Will keep you informed.

Thanks

Steve
 
J

Jeffrey Tan[MSFT]

Ok, I will wait for your further feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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