Problems with inheritance in vb.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pedro

    #1

    Problems with inheritance in vb.net

    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.Principa l.frmsdvPrincip al

    ....

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

    "The designer must create an instance of type
    'SDV.UL.Princip al.frmsdvPrinci pal' 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!
  • Marina

    #2
    Re: Problems with inheritance in vb.net

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

    "Pedro" <pnmm@portugalm ail.pt> wrote in message
    news:9f72c57b.0 407120455.59d4b b87@posting.goo gle.com...[color=blue]
    > 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.Principa l.frmsdvPrincip al
    >
    > ...
    >
    > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
    > error occurs;
    >
    > "The designer must create an instance of type
    > 'SDV.UL.Princip al.frmsdvPrinci pal' 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![/color]


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Problems with inheritance in vb.net

      * pnmm@portugalma il.pt (Pedro) scripsit:[color=blue]
      > 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.Principa l.frmsdvPrincip al
      >
      > ...
      >
      > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
      > error occurs;
      >
      > "The designer must create an instance of type
      > 'SDV.UL.Princip al.frmsdvPrinci pal' but it cannot because the type is
      > declared as abstract"[/color]

      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.

      --
      Herfried K. Wagner [MVP]
      <URL:http://dotnet.mvps.org/>

      Comment

      • Pedro

        #4
        Re: Problems with inheritance in vb.net

        "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=blue]
        > 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
        > --
        > David Williams, VB.NET MVP
        >
        >
        > "Herfried K. Wagner [MVP]" wrote:
        >[color=green]
        > > * pnmm@portugalma il.pt (Pedro) scripsit:[color=darkred]
        > > > 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.Principa l.frmsdvPrincip al
        > > >
        > > > ...
        > > >
        > > > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
        > > > error occurs;
        > > >
        > > > "The designer must create an instance of type
        > > > 'SDV.UL.Princip al.frmsdvPrinci pal' but it cannot because the type is
        > > > declared as abstract"[/color]
        > >
        > > 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.
        > >
        > > --
        > > Herfried K. Wagner [MVP]
        > > <URL:http://dotnet.mvps.org/>
        > >[/color][/color]


        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...

        Comment

        • Pedro

          #5
          Re: Problems with inheritance in vb.net

          "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=blue]
          > 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
          > --
          > David Williams, VB.NET MVP
          >
          >
          > "Herfried K. Wagner [MVP]" wrote:
          >[color=green]
          > > * pnmm@portugalma il.pt (Pedro) scripsit:[color=darkred]
          > > > 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.Principa l.frmsdvPrincip al
          > > >
          > > > ...
          > > >
          > > > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
          > > > error occurs;
          > > >
          > > > "The designer must create an instance of type
          > > > 'SDV.UL.Princip al.frmsdvPrinci pal' but it cannot because the type is
          > > > declared as abstract"[/color]
          > >
          > > 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.
          > >
          > > --
          > > Herfried K. Wagner [MVP]
          > > <URL:http://dotnet.mvps.org/>
          > >[/color][/color]


          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!

          Comment

          • Pedro

            #6
            Re: Problems with inheritance in vb.net

            "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=blue]
            > 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
            > --
            > David Williams, VB.NET MVP
            >
            >
            > "Herfried K. Wagner [MVP]" wrote:
            >[color=green]
            > > * pnmm@portugalma il.pt (Pedro) scripsit:[color=darkred]
            > > > 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.Principa l.frmsdvPrincip al
            > > >
            > > > ...
            > > >
            > > > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
            > > > error occurs;
            > > >
            > > > "The designer must create an instance of type
            > > > 'SDV.UL.Princip al.frmsdvPrinci pal' but it cannot because the type is
            > > > declared as abstract"[/color]
            > >
            > > 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.
            > >
            > > --
            > > Herfried K. Wagner [MVP]
            > > <URL:http://dotnet.mvps.org/>
            > >[/color][/color]


            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!

            Comment

            • Pedro

              #7
              Re: Problems with inheritance in vb.net

              pnmm@portugalma il.pt (Pedro) wrote in message news:<9f72c57b. 0407130241.6ade beb0@posting.go ogle.com>...[color=blue]
              > "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=green]
              > > 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
              > > --
              > > David Williams, VB.NET MVP
              > >
              > >
              > > "Herfried K. Wagner [MVP]" wrote:
              > >[color=darkred]
              > > > * pnmm@portugalma il.pt (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.Principa l.frmsdvPrincip al
              > > > >
              > > > > ...
              > > > >
              > > > > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
              > > > > error occurs;
              > > > >
              > > > > "The designer must create an instance of type
              > > > > 'SDV.UL.Princip al.frmsdvPrinci pal' 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.
              > > >
              > > > --
              > > > Herfried K. Wagner [MVP]
              > > > <URL:http://dotnet.mvps.org/>
              > > >[/color][/color]
              >
              >
              > 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![/color]

              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!

              Comment

              • Pedro

                #8
                Re: Problems with inheritance in vb.net

                pnmm@portugalma il.pt (Pedro) wrote in message news:<9f72c57b. 0407130241.6ade beb0@posting.go ogle.com>...[color=blue]
                > "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=green]
                > > 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
                > > --
                > > David Williams, VB.NET MVP
                > >
                > >
                > > "Herfried K. Wagner [MVP]" wrote:
                > >[color=darkred]
                > > > * pnmm@portugalma il.pt (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.Principa l.frmsdvPrincip al
                > > > >
                > > > > ...
                > > > >
                > > > > In run-time, frmsdvEtiquetas runs perfect, but in design time, this
                > > > > error occurs;
                > > > >
                > > > > "The designer must create an instance of type
                > > > > 'SDV.UL.Princip al.frmsdvPrinci pal' 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.
                > > >
                > > > --
                > > > Herfried K. Wagner [MVP]
                > > > <URL:http://dotnet.mvps.org/>
                > > >[/color][/color]
                >
                >
                > 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![/color]

                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!

                Comment

                • Jeremy Williams

                  #9
                  Re: Problems with inheritance in vb.net


                  "Pedro" <pnmm@portugalm ail.pt> wrote in message
                  news:9f72c57b.0 407131012.37bb5 a78@posting.goo gle.com...[color=blue]
                  > pnmm@portugalma il.pt (Pedro) wrote in message[/color]
                  news:<9f72c57b. 0407130241.6ade beb0@posting.go ogle.com>...[color=blue][color=green]
                  > > "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in[/color][/color]
                  message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=blue][color=green][color=darkred]
                  > > > What I tend to do when I run into issues like this (which is as[/color][/color][/color]
                  Herfried stated, you can not design a form that inherits from a MustInherit
                  class,) is to do something like:[color=blue][color=green][color=darkred]
                  > > >
                  > > > #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[/color][/color][/color]
                  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.[color=blue][color=green][color=darkred]
                  > > >
                  > > > HTH
                  > > > --
                  > > > David Williams, VB.NET MVP
                  > > >
                  > > >
                  > > > "Herfried K. Wagner [MVP]" wrote:
                  > > >
                  > > > > * pnmm@portugalma il.pt (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.Principa l.frmsdvPrincip al
                  > > > > >
                  > > > > > ...
                  > > > > >
                  > > > > > In run-time, frmsdvEtiquetas runs perfect, but in design time,[/color][/color][/color]
                  this[color=blue][color=green][color=darkred]
                  > > > > > error occurs;
                  > > > > >
                  > > > > > "The designer must create an instance of type
                  > > > > > 'SDV.UL.Princip al.frmsdvPrinci pal' but it cannot because the type[/color][/color][/color]
                  is[color=blue][color=green][color=darkred]
                  > > > > > 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[/color][/color][/color]
                  instantiate[color=blue][color=green][color=darkred]
                  > > > > the base class.
                  > > > >
                  > > > > --
                  > > > > Herfried K. Wagner [MVP]
                  > > > > <URL:http://dotnet.mvps.org/>
                  > > > >[/color]
                  > >
                  > >
                  > > 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![/color]
                  >
                  > 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![color=green]
                  > > Thanks in advance![/color][/color]

                  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.


                  Comment

                  • Jeremy Williams

                    #10
                    Re: Problems with inheritance in vb.net


                    "Pedro" <pnmm@portugalm ail.pt> wrote in message
                    news:9f72c57b.0 407131012.37bb5 a78@posting.goo gle.com...[color=blue]
                    > pnmm@portugalma il.pt (Pedro) wrote in message[/color]
                    news:<9f72c57b. 0407130241.6ade beb0@posting.go ogle.com>...[color=blue][color=green]
                    > > "David Williams" <DavidWilliams@ discussions.mic rosoft.com> wrote in[/color][/color]
                    message news:<99A82562-3808-4F23-8005-EFE411FA2F67@mi crosoft.com>...[color=blue][color=green][color=darkred]
                    > > > What I tend to do when I run into issues like this (which is as[/color][/color][/color]
                    Herfried stated, you can not design a form that inherits from a MustInherit
                    class,) is to do something like:[color=blue][color=green][color=darkred]
                    > > >
                    > > > #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[/color][/color][/color]
                    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.[color=blue][color=green][color=darkred]
                    > > >
                    > > > HTH
                    > > > --
                    > > > David Williams, VB.NET MVP
                    > > >
                    > > >
                    > > > "Herfried K. Wagner [MVP]" wrote:
                    > > >
                    > > > > * pnmm@portugalma il.pt (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.Principa l.frmsdvPrincip al
                    > > > > >
                    > > > > > ...
                    > > > > >
                    > > > > > In run-time, frmsdvEtiquetas runs perfect, but in design time,[/color][/color][/color]
                    this[color=blue][color=green][color=darkred]
                    > > > > > error occurs;
                    > > > > >
                    > > > > > "The designer must create an instance of type
                    > > > > > 'SDV.UL.Princip al.frmsdvPrinci pal' but it cannot because the type[/color][/color][/color]
                    is[color=blue][color=green][color=darkred]
                    > > > > > 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[/color][/color][/color]
                    instantiate[color=blue][color=green][color=darkred]
                    > > > > the base class.
                    > > > >
                    > > > > --
                    > > > > Herfried K. Wagner [MVP]
                    > > > > <URL:http://dotnet.mvps.org/>
                    > > > >[/color]
                    > >
                    > >
                    > > 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![/color]
                    >
                    > 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![color=green]
                    > > Thanks in advance![/color][/color]

                    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.


                    Comment

                    Working...