MustInherit give a problem

  • Thread starter Thread starter Academia
  • Start date Start date
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
 
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
 
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
 
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.
 
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.
 
Back
Top