Form Inhertiance Sometimes Not Working

S

Selden McCabe

I'm having some strange trouble with form inheritance.
FormA inherits FormB. The New method in FormA
passes an object to FormB via it's New method. The New
method of FormB then creates some other objects, several
of which reference the object just passed in.

This will be working just fine, then suddenly when I try to
open FormA in the IDE, I get "An error occurred while loading
the document. ..." Then
"Object reference not set to an instance of an object."

Even when it's in this state, I can run the project, and FormA shows
up just fine!

Sometimes I'm able to get things working again by referencing FormB
as a DLL instead of a project, but that doesn't always do the trick.

What am I doing wrong, and how can I get it to recover when this
happens?

Thanks for any tips!
---Selden McCabe
 
C

CJ Taylor

This is actually a designer issue.

You call new, which instantiates certian objects I'm sure. The designer
(correct me if I'm wrong) calls the InitializeComponent Subroutine (from
New) in which case it creates all the objects that need to be done.

However, the designer only calls the non-overloaded version of the
constructor I believe, which could be why you are having problems... I ran
across the same thing, and had to do some stuff with IContainer...

I may be wrong, but it helped me.

-CJ
 
S

Selden McCabe

Thanks, to both of you for replying. Your answers, plus some other posts
here
helped me figure it out. Here's what it was, in case anyone else has the
same problem:

CJ Taylor was right! When you load an inherited form in the designer, it's
native
New method gets called, which then cannot pass an object to the base form.

The answer is to make sure both calls will work. In the normal case, New
from the
inherting form calls New on the inherited form, passing an object which, in
this case,
was used to derive other objects. So I added code in the native New method
of the
base form to instantiate the objects I needed. Problem solved!

Thanks again, you guys are great!
 
C

CJ Taylor

Rock on!

First the cubs win! And then I solve a pretty diffucult problem well!

Bling Bling ya'll!
 

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