Foundation...Ac cessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.
How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?
I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly, searching for the answer.
Thanks in advance... 6 1850
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?
Could you give some more information?
..ARN.
"DelGator" wrote: Foundation...Ac cessing derived class members through a variable of their base class is just a matter of casting the variable to the derived class.
How would you access the derived class members in a collection of type base class where the collection is derived from CollectionBase?
I know that I'm going to feel like a fool when this is resolved, but I have racked my brain, and almost brought down the Google servers, single-handedly, searching for the answer.
Thanks in advance...
It's not clear what you're trying to do here. Are you trying to access items
that have been added to a collection class derived from CollectionBase? Or
have you added member variables to the derived class that you're trying to
access?
Could you give some more information?
..ARN.
"DelGator" wrote: Foundation...Ac cessing derived class members through a variable of their base class is just a matter of casting the variable to the derived class.
How would you access the derived class members in a collection of type base class where the collection is derived from CollectionBase?
I know that I'm going to feel like a fool when this is resolved, but I have racked my brain, and almost brought down the Google servers, single-handedly, searching for the answer.
Thanks in advance...
Sorry...
I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow" . I have also created a "Row" type collection class, based
on CollectionBase.
The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.
I know how to access the derived class members when dealing with simple
base class variables. You would cast...
(FileRow)Row.de rivedClassPrope rty
What I need is the process for accessing them inside the collection.
Hope this is clearer.
Thanks in advance...
Sorry...
I have a base class, let's call it a "Row", that I have created derived
classes from. So, let's call the derived classes "FileRow" and
"CookieRow" . I have also created a "Row" type collection class, based
on CollectionBase.
The derived classes, "FileRow" and "CookieRow" have additional
properties from those inherited from "Row". I want to be able to access
those additional properties from within the collection.
I know how to access the derived class members when dealing with simple
base class variables. You would cast...
(FileRow)Row.de rivedClassPrope rty
What I need is the process for accessing them inside the collection.
Hope this is clearer.
Thanks in advance...
Based on your further explanation, I think that the following may help.
Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:
public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fi leInt;
else
dRow = ((CookieRow)r). cookieInt;
}
}
The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.
I hope this helps.
..ARN.
"DelGator" wrote: Sorry...
I have a base class, let's call it a "Row", that I have created derived classes from. So, let's call the derived classes "FileRow" and "CookieRow" . I have also created a "Row" type collection class, based on CollectionBase.
The derived classes, "FileRow" and "CookieRow" have additional properties from those inherited from "Row". I want to be able to access those additional properties from within the collection.
I know how to access the derived class members when dealing with simple base class variables. You would cast...
(FileRow)Row.de rivedClassPrope rty
What I need is the process for accessing them inside the collection.
Hope this is clearer.
Thanks in advance...
Based on your further explanation, I think that the following may help.
Let's suppose the FileRow class has an integer called fileInt and the
CookieRow class has an int called cookieInt. Suppose the collection class
has a method called DoSomething(). Then you could do something like the
following:
public void DoSomething()
{
foreach( Row r in this )
{
int dRow;
if( r is FileRow )
dRow = ((FileRow)r).fi leInt;
else
dRow = ((CookieRow)r). cookieInt;
}
}
The key here is the if( r is FileRow) statement. This identifies r as in
instance of the FileRow class. Then you use the (odd-looking) cast to get to
the FileRow member field.
I hope this helps.
..ARN.
"DelGator" wrote: Sorry...
I have a base class, let's call it a "Row", that I have created derived classes from. So, let's call the derived classes "FileRow" and "CookieRow" . I have also created a "Row" type collection class, based on CollectionBase.
The derived classes, "FileRow" and "CookieRow" have additional properties from those inherited from "Row". I want to be able to access those additional properties from within the collection.
I know how to access the derived class members when dealing with simple base class variables. You would cast...
(FileRow)Row.de rivedClassPrope rty
What I need is the process for accessing them inside the collection.
Hope this is clearer.
Thanks in advance...
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: m.pollack |
last post by:
Hi all,
I have an application which uses a class object that
contains a collection. In order to use the PropertyGrid
control to expose properties to the user at runtime, I
created a strongly-typed collection class based on
CollectionBase. However, when I use the PropertyGrid to
remove objects from the collection at runtime via the
popup Object Collection Editor, it appears that the "On*"
(CollectionBase.OnRemove and
|
by: Mike Pollett |
last post by:
Hi, I have used the ISerializable interface before and the code below worked
fine. Until I derived it from CollectionBase. The code will still serialize
and deserialize the properties in this class and properties derived from
this class but will not serialize or deserialize the properties in
CollectionBase. Like InnerList, which is a read only property of
CollectionBase.
How can I serialize and deserialize the InnerList property of...
|
by: Mike Pollett |
last post by:
Hi, I have used the ISerializable interface before and the code below worked
fine. Until I derived it from CollectionBase. The code will still serialize
and deserialize the properties in this class and properties derived from
this class but will not serialize or deserialize the properties in
CollectionBase. Like InnerList, which is a read only property of
CollectionBase.
How can I serialize and deserialize the InnerList property of...
|
by: Eric Johannsen |
last post by:
I have a simple object that inherits from CollectionBase and overrides the
Count property:
namespace MyTest
{
public class CollTest : System.Collections.CollectionBase
{
public override int Count
{
get { return 0; }
|
by: DelGator |
last post by:
Foundation...Accessing derived class members through a variable of
their base class is just a matter of casting the variable to the
derived class.
How would you access the derived class members in a collection of type
base class where the collection is derived from CollectionBase?
I know that I'm going to feel like a fool when this is resolved, but I
have racked my brain, and almost brought down the Google servers,
single-handedly,...
| |
by: jason |
last post by:
Hello. I've got this simple collection populate code I downloaded from
the net (sorry can't find source now) I'm trying to test, but I can't
seem to get it to work. Any help would be greatly appreciated.
I've compiled the following VB.NET into a DLL:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
|
by: Matthew Roberts |
last post by:
Howdy Everyone,
I am having trouble understanding the process of creating a type-safe
collection by inheriting from the CollectionBase class. I have done it
plenty of times, but now that I sit down and look at it, I'm wondering
why it behaves the way it does, and also how to improve its
functionality.
First, understand the basic format of a type-safe collection:
|
by: Kyle Novak |
last post by:
I have a question about strongly typed objects when looping through a
collection based on the CollectionBase object and using a For..Each loop.
I have 2 objects:
-Invoice: Holds all properties related to an invoice
-InvoiceCollection: Inherited from Collectionbase class and holds Invoice
objects
The InvoiceCollection class is as follows:
|
by: Yuk Tang |
last post by:
I am tearing my hair out over this, since I can't see what I'm doing
wrong (duh, if I knew, I wouldn't be asking the question). I am
adding Field items to a Field Collection, but for some reason it
wants to start from the beginning and overwrite all entries before
adding the latest member. I've added a couple of msgboxes to
illustrate this, one at the add method, another cycling through the
collection after the addition has been made.
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |