Problems with inheritance in vb.net

P

Pedro

Hi, all.


I'm having a problem which vb developers had for certain al least
once.

I have my base form, declared as musthinherit;

Public MustInherit Class frmsdvPrincipal

....

and my child form, declared as inherited;

Public Class frmsdvEtiquetas
Inherits SDV.UL.Principal.frmsdvPrincipal

....

In run-time, frmsdvEtiquetas runs perfect, but in design time, this
error occurs;

"The designer must create an instance of type
'SDV.UL.Principal.frmsdvPrincipal' but it cannot because the type is
declared as abstract"

I've tryed several tips like deleting the reference and adding it
again and excluding the child form and including it again, but nothing
works....

Can someone help me? What am i doing wrong?

URGENT!!!

Thanks in advance!
 
M

Marina

I think this is a designer issue. Don't make the base class abstract and it
should go away.
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Pedro) scripsit:
I have my base form, declared as musthinherit;

Public MustInherit Class frmsdvPrincipal

...

and my child form, declared as inherited;

Public Class frmsdvEtiquetas
Inherits SDV.UL.Principal.frmsdvPrincipal

...

In run-time, frmsdvEtiquetas runs perfect, but in design time, this
error occurs;

"The designer must create an instance of type
'SDV.UL.Principal.frmsdvPrincipal' but it cannot because the type is
declared as abstract"

You cannot edit a form that inherits from a mustinherit form in the
windows forms designer because the designer must be able to instantiate
the base class.
 
P

Pedro

David Williams said:
What I tend to do when I run into issues like this (which is as Herfried stated, you can not design a form that inherits from a MustInherit class,) is to do something like:

#If DEBUG Then
Public Class fmsdvPrincipal
#Else
Public MustInherit frmsdvPrincipal
#End If

However, there MIGHT be a problem with that in this case. If the class has any routines that you marked as MustOverride, you will have to change them, possiblly by wrapping in an #If as above, to Overridable and give no implementation details.

HTH


Thanks David;

Your suggestion works, but when i run my solution, a similar problem
with base form occurs.

Sometimes i have to comment the #if #else #endif code, close the
solution, open it again and both base and child form appears to open
in design mode.
After running my project once, the problem with child form appears...
That's when i uncomment the #if #else #endif code to resolve it. And
so on, and so on... Basically, i can have my base and child form
running on design mode, but only when i follow this steps and before
running my project.

Is this normal?

Thanks for the tip David...
 
P

Pedro

David Williams said:
What I tend to do when I run into issues like this (which is as Herfried stated, you can not design a form that inherits from a MustInherit class,) is to do something like:

#If DEBUG Then
Public Class fmsdvPrincipal
#Else
Public MustInherit frmsdvPrincipal
#End If

However, there MIGHT be a problem with that in this case. If the class has any routines that you marked as MustOverride, you will have to change them, possiblly by wrapping in an #If as above, to Overridable and give no implementation details.

HTH


Hi!

I think i figure a way to control this inheritance issue in design/run
time, with your advances, but this design issue in vb.net is very
anoying! Now, i can't see my child form controls in run-time. They
appear normally in design but not in run-time! Why?

Any ideas?

Thanks in advance!
 
P

Pedro

Hi!

I think i figure a way to control this inheritance issue in design/run
time, with your advances, but this design issue in vb.net is very
anoying! Now, i can't see my child form controls in run-time. They
appear normally in design but not in run-time! Why?

Any ideas?

Thanks in advance!

Sorry i wasn't very specific in the latest post! My child form
inherits anything from my base form. What i want is to add some
controls (not inherited) to my child form, but they only appear in
design! Why is that?

Help needed!

Thanks in advance!
 
J

Jeremy Williams

Pedro said:
(e-mail address removed) (Pedro) wrote in message
Herfried stated, you can not design a form that inherits from a MustInherit
class,) is to do something like:class has any routines that you marked as MustOverride, you will have to
change them, possiblly by wrapping in an #If as above, to Overridable and
give no implementation details.
Sorry i wasn't very specific in the latest post! My child form
inherits anything from my base form. What i want is to add some
controls (not inherited) to my child form, but they only appear in
design! Why is that?

Help needed!

Are you adding the controls to a panel or other container? If so, you need
to make sure the container control's modifier is not set to Private in the
base form (preferably, it would be set to Protected). The behavior you
describe happens when the modifier is set to Private.
 

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