Cast Inherited To Base Class?

May 19, 2010

The program below trhows an error in the line "mTable2 = mTable.Copy". The error is: "Unable to cast object of type 'System.Data.DataTable' to type InherintanceQuestion.InheritedTable". This is because mTables is an instance of the InheritedTable class which inherits a DataTable and mTable is a DataTable. So, is there any way I can create the mTable2 to the mTable.copy to the mTable.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[code].....

View 2 Replies


ADVERTISEMENT

Does An Inherited Class Automatically Implement An Interface From Its Base Class

Jun 10, 2011

Suppose I have piece of code like this:

Public Interface ISomething
....
End Interface

[code]....

View 2 Replies

Returning A Inherited Class As Base Class Type With Web Services?

Sep 25, 2009

I suspect I am being very silly here but I have the following setup

Class MustInherit myBaseClass
'some stuff
End Class
Class myInheritedClassA

[code]....

Running this results in the following error

Unhandled Exception: System.InvalidOperationException:
There was an error generating the XML document. --->
System.InvalidOperationException:

[code]....

is there any way of 'Widening' the inherited class to the base class so this would work?

EDIT:regarding XmlInclude(typeof inheritedClass), currently this method could potentially return a number of types of inherited class (i.e myInheritedClassA and myInheritedClassB) is it case of simply having to add each of the inheritedTypes in this tag?

View 2 Replies

Convert From Base Class To Inherited Class?

Jun 2, 2009

I understand that inherited classes can't be converted from base classes. But is there any way to write a conversion sub, so that the base class gets assigned to MyBase, then extra properties are added?[code]...

View 7 Replies

[2008] Base Class Inherited By 2 Derived Classes

Jan 30, 2009

i've finally got round to learning about classes and inheritance, but i'm not sure how to proceed. i have a base class Employee, which is inherited by 2 derived classes. how do i use the same Employee class in both derived classes? obviously if i write a sub new for both of them + declare a new Employee class, they won't be using the same class. heres my Employee class:

[Code]....

View 7 Replies

"upgrade" An Object To An Inherited Class, And Keep All The Base Class's Property Values?

Jul 5, 2010

bare with me during this silly example. :-) Let's say I have a class like this:

Public Class Animal
Public iLegs as int32 ' Number of legs
Public bWings as Boolean ' Wings? Yes/No
End Class

And another class that inherits the "Animal" class and adds one more property:

Public Class ScaryAnimal
Inherits Animal
Public iScariness as int32 ' 0-100, how scary is it?
End Class

Now, if I have an instance of "Animal" with some values in it, and I decide I want to cast it to a ScaryAnimal for some reason, how do I do that without having to create a new instance of "ScaryAnimal" and copy each property value?Basically I'm looking for a way to do this, without having to write the lines marked with '*** below:

[Code]...

View 2 Replies

VS2008/VB: Moving Subclass VB Code To Inherited Base Class - Where Should Variables/objects Be Declared

Jun 3, 2009

In re-engineering a windows forms application, I find that a lot of code-behind in the various form classes is duplicative and I'm trying to centralize as many procedures as possible into a base class which can be inherited and used by the subclassed forms.

This process seems to be going well and is making the code in my subclasses much simpler and hopefully easier to maintain, but I'm not sure where to draw the line between leaving code in the subclasses and engineering for generic resusability and moving it to the base class.

Specifically, in some subclasses I have code which manipulates variables and objects specific to the subclass, and although I could move the code-behind into the base class, the base class code references specific objects which are needed to compile. For example, each subclass manipulates a databound datagridview and form detail controls which allows the user to select between multi-record and detailed single-record views of a datatable.

In Visual Basic 2008 do I need to declare dummy data objects in the base class so that the base class will compile? Or is there a way to indicate that the data objects will be provided by the subclass?

View 13 Replies

Base Form And Inherited Other Forms From It - Don't See Those Changes Take Effect In My Inherited Forms?

Jun 24, 2010

I have a base form and I inherit other forms from it. However, if i go back and change say the size of the base form, I don't see those changes take effect in my inherited forms. Does anyone know why that is? Is there a solution to this issue?So as far as design is goes, what exactly gets inherited by other forms?

View 9 Replies

Invalid Cast While Using Inherited Classes?

Jul 28, 2010

I create an application in both C#.NET and VB.NET

When I inherit a C# class in VB I want to be able to set an instance of the VB class to be equal to that from a C# instance.

public
class
SomeClass

[Code].....

View 5 Replies

Passing Base Object Type When Using Inherited One?

Oct 8, 2010

I have a project that has mainly two objects, both inheriting from a base. Like this:

Public Class Vehicle
Property Model As String
Property Make As String[code].....

The above function doesn't work because myVehicle is a Vehicle, not a Truck.Is there a way I can pass around a Vehicle type and have the IDE know which type to use? Or am I completely missing a better way to do this?

View 5 Replies

.net - Extending ENUM Valus Inherited From Base Object?

Jun 14, 2010

If I defined a ENUM in a base object with serveral default values. When I inherit from the base object I want to add more options the the ENUM list which are specific to the inheriting object.

For example my base could have a ENUM called Direction with values:
None
ALL
Stop
Start

I create a new class call Compass which inherits the base class and what to add the following to the ENUM Direction. I create a new class call Navigation which inherits the base class and what to add the following to the ENUM Direction. So, In my inheriting class haow do I extend the ENUM.

View 1 Replies

Handling The Paint Event In The Base And Inherited Forms?

Sep 21, 2010

I have a form called BaseReportForm that handles drawing some stuff to in a panel to create a template for a bunch of reports. The drawing all takes place in the Panel's Paint event and this form will always be inherited. In the inherited forms, I draw the specific details of the report in the inherited form's Panel Paint event. So I am drawing to the same panel from the base form and from the inherited form. It all works fine, but when I try to open the design view for the inherited forms, I get the following error..

Quote:

The event Paint is read-only and cannot be changed.

I'm not sure I am handling my paint events correctly. Is there a different way I should be handling the drawing of these reports?

View 9 Replies

Error - Base Class 'System.Windows.Forms.Panel' Specified For Class 'MenuButton' Cannot Be Different From The Base Class 'System.Windows.Forms.UserControl'

Mar 12, 2010

When I do this

Public Class cInherits : Inherits Panel

I get this: Base class 'System.Windows.Forms.Panel' specified for class 'MenuButton' cannot be different from the base class 'System.Windows.Forms.UserControl' of one of its other partial types.

How do I inherit?

View 4 Replies

Get An Enum To Explicitly Cast To It's Base Type?

Mar 9, 2010

Is there a way to get an enum to explicitly cast to it's base type?If I have something like this:

Code:
Public Enum Packets As Byte
Stuff = &H0
End Enum

I have to do

Code:
Dim test As Byte = CByte(Packets.Stuff)

Rather than

Code:
Dim test As Byte = Packets.Stuff

I don't see why that's the way it works, since you know that the enum will always have values of the base type.

View 4 Replies

Form Inheritance - Error1Base Class 'MenuStrip' Specified For Class 'Lesson2' Cannot Be Different From The Base Class

Apr 15, 2010

I have put this code in the global form Inherits System.Windows.Forms.Form. And then in the form that will inherit this from the global Inherits MenuStrip. "MenuStrip" is what the global form is called. But keep getting this error: Error1Base class 'MenuStrip' specified for class 'Lesson2' cannot be different from the base class 'System.Windows.Forms.Form' of one of its other partial types.

View 5 Replies

Force An Inherited Class To Use An Attribute On The Class?

Oct 29, 2009

I'm trying to force an inherited class to use a custom attribute. I'm creating a class library where the user who wants to create an item will do so, but be forced to add an attribute (or visual studio will automatically add the default attribute) to their inherited class. Here is what I'm hoping to achieve:

BaseClass.vb:
<CustomAttribute(10)> _
Public Class BaseClass
End Class
MyClass.vb:

[Code]...

View 2 Replies

C# - How To Prevent Class 'a' From Being Inherited By Another Class

Jul 31, 2010

i have a class named fdetails and i do not want any other class to inherit from this classCan i set it to not being inherited by another class. I would like to get the things done in the following 3 languages

View 6 Replies

Prevent Class 'a' From Being Inherited By Another Class?

May 23, 2010

i have a class named fdetails and i do not want any other class to inherit from this classCan i set it to not being inherited by another class. I would like to get the things done in the following 3 languages

View 5 Replies

Create A New Class That Inherits From The Base Form Class And Define A New() Method With Parameters?

Oct 1, 2008

I've been creating short test apps repeatedly to try to understand some of the concepts in VB.NET.For the most part it has been illuminating.I read Bucky's .NET knowlegebase tutorial on passing objects as parameters to newly created forms. He shows how to create a new class that inherits from the base form class and define a New() method with parameters Extending the concept I thought about doing the same thing with a form that was created at design-time (In this case Form2).

[Code]...

View 6 Replies

Call Method Base Class In Program Passing Sub Class Objects?

Apr 22, 2012

Base class has one field to hold numeric balance value. With 2 methods that accept arguments for adding and subtracting the new input calculating new balance. Sub class has four fields dates, transaction, memo and amount.I have a deposit form, and withdraw form. Each time one transaction is entered it creates an object with sub class fields, then adds to the account collection. My problem is not understanding how to call the deposit/withdraw method and pass the current transaction amount back to the base class to alculate the new balance. Does anyone have any links to information/tutorials on how to perform something like this? As you can see with my code I have tried various different approaches without any success.

[Code]...

View 5 Replies

.net - Suppress A Property Or Method From A Base-class In A Derived Class?

Apr 7, 2011

Supose a base class

Public Class airplane
Private var_num_seats As Integer
Private var_num_engines As Integer

[code]....

Obviously, I don't wish that the class Glider has the method "start_engines" neither the property "num_engines". Otherwise, other child classes may have. How can I supress these property and method in child class, not just ignoring (if I can)?

View 2 Replies

.NET Class Inherits A Base Class And Implements An Interface (works In C#)?

Apr 9, 2010

I am trying to create a class in VB.NET which inherits a base abstract class and also implements an interface. The interface declares a string property called Description. The base class contains a string property called Description. The main class inherits the base class and implements the interface. The existence of the Description property in the base class fulfills the interface requirements. This works fine in C# but causes issues in VB.NET.

[Code]...

View 5 Replies

Can't Inherit Shared Properties From A Base Class In A Child Class?

Dec 29, 2010

This is another one of my "I think it's not possible but I need confirmation" questions.I have a base class for a bunch of child classes. Right now, this base class has a few common properties the children use, like Name. The base is an abstract class (MustInherit)Technically, this means that everytime a child class is instantiated, it lugs around, in memory, its own copy of Name. The thing is, Name is going to be a fixed value for all instances of a given child. I.e., Child1.Name will return "child_object1", and Child2.Name will return "child_object2".

View 1 Replies

Access Class From Inherited?

Oct 14, 2011

I have two classes[code]...

How can I modify class1 in a sub in class2?

View 2 Replies

Access The Base Class Inside A Derived Class?

Oct 22, 2010

How do I access the base class inside a derived class?

View 1 Replies

Get Base Class Object Reference Outside The Class's Definition?

Dec 10, 2010

If we are within the derived class then ofcource we can use MyBase keyword to access base class's object reference . That's fine , how can we take that base class's object reference outside that derived class's definition.My following code will explain what i want . Actually that is giving error right now, but it is explaining my requirement .

Public Class Base
Public x As String
End Class

[code]....

Actually there is error in ReadOnly Property BaseReference's Getter . Error is "Error 1 'MyBase' must be followed by '.' and an identifier. " how can i get base class object reference in Main method ?

View 1 Replies

Generic Inherited Class Definition

Jan 11, 2010

I'm having trouble with the definition of an inherited generic class. I have two base classes that are defined like this:[code]

View 2 Replies

Hide A Method In An Inherited Class?

Feb 13, 2010

Is there a way to hide a method of a base class that has been inherited?Lets say the base class has the properties:

x
y
Height
Width

and the method

sub SpecialInstructions()

Now this class is inherited by some classes that either use the SpecialInstructions method or override it. But one class inherits it but cant make use of the method and therefore wants to hide it. I tried shadowing but it still seems that the method is visible ex

Private Shadows Sub SpecialInstructions()

View 9 Replies

Inherited Class Designer Locked ?

Dec 30, 2009

I have a class which inherits a form class, and just recently it's started acting strange. All of the controls on the form are locked, and I don't understand why. I can't edit the properties of any controls, or anything.

View 4 Replies

Narrowing The Scope Of Sub In Inherited Class?

Apr 5, 2011

Below is example code of what I want to do:

Public Class Test
Sub New()
Dim cool As New B
cool.Doit()

[code]....

View 6 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved