473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Collections Problem

Hi All,

I've got a problem with the following example test code crashing,
complaining that the object reference is not set (.NET 1.1). Basically, I
instantiate a
collection of objects and begin populating the collection with appropriate
objects, then print them out. What am I doing wrong to cause the crash?
Seems like it should be obvious, but I'm not seeing it.

private void Form1_Load(object sender, System.EventArgs e)
{
MyObjCollection moc = new MyObjCollection();
MyObj mo1 = new MyObj("Object1");
moc.Add(mo1);
MyObj mo2 = new MyObj("Object2");
moc.Add(mo2);
foreach(MyObj obj in moc)
{
MessageBox.Show(obj.MyVar1);
}
}

internal sealed class MyObj
{
private string m_MyVar1 = "FooBar";
internal MyObj(string MyVar1)
{
m_MyVar1 = MyVar1;
}

internal string MyVar1
{
get
{
return m_MyVar1;
}

}
}

internal sealed class MyObjCollection : BaseCollection
{
internal MyObjCollection()
{
}

internal void Add(MyObj obj)
{
this.List.Add(obj);
}
}
Any help would be much appreciated. TIA,

--
John Bowman
Verona, WI
18*******@charter.net
Nov 17 '05 #1
2 1157
Hi John,
on which line are you seeing this problem. I just copied your code and it
ran fine, well except for having to change BaseCollection to CollectionBase,
not sure if that was a typo or you have some other class you have defined.

Mark.

"John Bowman" wrote:
Hi All,

I've got a problem with the following example test code crashing,
complaining that the object reference is not set (.NET 1.1). Basically, I
instantiate a
collection of objects and begin populating the collection with appropriate
objects, then print them out. What am I doing wrong to cause the crash?
Seems like it should be obvious, but I'm not seeing it.

private void Form1_Load(object sender, System.EventArgs e)
{
MyObjCollection moc = new MyObjCollection();
MyObj mo1 = new MyObj("Object1");
moc.Add(mo1);
MyObj mo2 = new MyObj("Object2");
moc.Add(mo2);
foreach(MyObj obj in moc)
{
MessageBox.Show(obj.MyVar1);
}
}

internal sealed class MyObj
{
private string m_MyVar1 = "FooBar";
internal MyObj(string MyVar1)
{
m_MyVar1 = MyVar1;
}

internal string MyVar1
{
get
{
return m_MyVar1;
}

}
}

internal sealed class MyObjCollection : BaseCollection
{
internal MyObjCollection()
{
}

internal void Add(MyObj obj)
{
this.List.Add(obj);
}
}
Any help would be much appreciated. TIA,

--
John Bowman
Verona, WI
18*******@charter.net

Nov 17 '05 #2
Mark,

Man, do I feel like a dummy. That was it. You hit the nail on the head. I
should be using CollectionBase not BaseCollection. Apparently, I got those 2
base classes mixed up in my head and tried to use the wrong base class to
inherit form.
Many thanks!

John

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:D9**********************************@microsof t.com...
Hi John,
on which line are you seeing this problem. I just copied your code and
it
ran fine, well except for having to change BaseCollection to
CollectionBase,
not sure if that was a typo or you have some other class you have defined.

Mark.

"John Bowman" wrote:
Hi All,

I've got a problem with the following example test code crashing,
complaining that the object reference is not set (.NET 1.1). Basically, I
instantiate a
collection of objects and begin populating the collection with
appropriate
objects, then print them out. What am I doing wrong to cause the crash?
Seems like it should be obvious, but I'm not seeing it.

private void Form1_Load(object sender, System.EventArgs e)
{
MyObjCollection moc = new MyObjCollection();
MyObj mo1 = new MyObj("Object1");
moc.Add(mo1);
MyObj mo2 = new MyObj("Object2");
moc.Add(mo2);
foreach(MyObj obj in moc)
{
MessageBox.Show(obj.MyVar1);
}
}

internal sealed class MyObj
{
private string m_MyVar1 = "FooBar";
internal MyObj(string MyVar1)
{
m_MyVar1 = MyVar1;
}

internal string MyVar1
{
get
{
return m_MyVar1;
}

}
}

internal sealed class MyObjCollection : BaseCollection
{
internal MyObjCollection()
{
}

internal void Add(MyObj obj)
{
this.List.Add(obj);
}
}
Any help would be much appreciated. TIA,

--
John Bowman
Verona, WI
18*******@charter.net

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: aa7im | last post by:
I am trying to design a good domain model for a system I am working on but I am having a hard time trying to figure out how to deal with relations and transaction... For example if I create an...
2
by: a | last post by:
The problem: I want to allow an administrator (user) to create a list of teachers, each teacher in turn has a list of classes, each class has a list of students. There's an article at...
4
by: Adam Clauss | last post by:
I ran into a problem a while back when attempting to convert existing .NET 1.1 based code to .NET 2.0 using Generic collections rather than Hashtable, ArrayList, etc. I ran into an issue because...
11
by: CMM | last post by:
First let me say that maybe I'm having a "duh" moment and perhaps I'm missing something... but it seems to me that no one thing in the System.Collections namespace (even in .NET 2.0) even comes...
0
by: bearophileHUGS | last post by:
Several languages like Java, C# etc have a List type in the std lib. Python has a built-in list(), it's implemented as array dynamic on the right. Not too much time ago Hettinger has added a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.