MustInherit give a problem

A

Academia

I create a form

Public Class MyTool

Inherits MyForm

....

which uses:

Public MustInherit Class MyForm

Inherits Form

....

The reason for the MustInherit is that the MyForm contains:
Protected Friend MustOverride Sub SetThis()



And get the error:

The designer must create an instance of type 'Test.Lib.MyForm' but it cannot
because the type is declared as abstract.

If I change to an Overridable sub and remove the MustInherit it works OK.

I prefer the MustOverride because then I can't forget to override it when I
use MyForm.

Can you advise or shed some light on this?


Thanks
 
A

Armin Zingler

Academia said:
I create a form

Public Class MyTool

Inherits MyForm

...

which uses:

Public MustInherit Class MyForm

Inherits Form

...

The reason for the MustInherit is that the MyForm contains:
Protected Friend MustOverride Sub SetThis()



And get the error:

The designer must create an instance of type 'Test.Lib.MyForm' but
it cannot because the type is declared as abstract.

If I change to an Overridable sub and remove the MustInherit it
works OK.

I prefer the MustOverride because then I can't forget to override it
when I use MyForm.

Can you advise or shed some light on this?


You can not create an instance of an abstract class, thus the designer
can't, too. You would have to remove "Mustinherit". I don't think there's
another way. If you go for it, you might throw a
System.NotImplementedException in Sub SetThis in the base class. Not what
you're looking for, I know.


Armin
 
A

Academia

Why is the designer creating an instance of MyForm. I'd think it would
create an instance of MyTool which normally can create a MyForm object.

Thanks
 
J

Jack Jackson

The designer creates an instance of the base class and then runs the
InitializeComponents method from the current class.

I believe I read that this is fixed in VS2008.
 
A

Academia

thanks

Jack Jackson said:
The designer creates an instance of the base class and then runs the
InitializeComponents method from the current class.

I believe I read that this is fixed in VS2008.
 

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