473,320 Members | 1,909 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,320 software developers and data experts.

Registering/deregistering object with list

A Person can belong to one group.
I want to be able to set the group using these two methods:

PersonA.Group = GroupA

or

GroupA.Add(PersonA)

In the Set method of Person.Group, the Person adds itself to the
Groups list:
Set
_Group.Remove(Me) ' Remove self from previous group
value.Add(Me) ' Add self to new group
_Group = value ' Set field
End Set

So when using PersonA.Group = GroupA, PersonA has knowledge of what
group it belongs to, and it also registers with GroupA.
So immediately after doing:
PersonA.Group = GroupA,
....the following is true:
GroupA.Contains(PersonA) = True.

Coming the other direction, when saying: GroupA.Add(PersonA), I have
in a OnListChanged sub of the Group class:
(pseudo code)
Sub ListChanged(e)
if e.ChangeType = Add Then
e.Person.Group= Me
ElseIf e.ChangeType = Delete
e.Person.Group= Nothing
End If
End Sub

So after doing:
GroupA.Add(Person)
....the following is true:
PersonA.Group = GroupA.

The problem is that this creates an infinite loop. When Something is
added/removed to Group, the Person.Group setter is called. And when
the Person.Group setter is called, it triggers the Group ListChanged
event.

I am working on a messy solution with shared variables that allow the
ListChanged subs let the Person.Group setter know that it is being set
by the ListChanged event, and vice versa so they don't call each
other.
I am looking for a clean pattern. How would you solve this problem?

Oct 1 '08 #1
1 993
Hi Bryan,

try changing the set to:

Set
If value Is _Group Then return
If _Group IsNot Nothing Then _Group.Remove(Me)
value.Add(Me) ' Add self to new group
_Group = value ' Set field
End Set

"Bryan" <br*******@gmail.comwrote in message
news:66**********************************@t41g2000 hsc.googlegroups.com...
>A Person can belong to one group.
I want to be able to set the group using these two methods:

PersonA.Group = GroupA

or

GroupA.Add(PersonA)

In the Set method of Person.Group, the Person adds itself to the
Groups list:
Set
_Group.Remove(Me) ' Remove self from previous group
value.Add(Me) ' Add self to new group
_Group = value ' Set field
End Set

So when using PersonA.Group = GroupA, PersonA has knowledge of what
group it belongs to, and it also registers with GroupA.
So immediately after doing:
PersonA.Group = GroupA,
...the following is true:
GroupA.Contains(PersonA) = True.

Coming the other direction, when saying: GroupA.Add(PersonA), I have
in a OnListChanged sub of the Group class:
(pseudo code)
Sub ListChanged(e)
if e.ChangeType = Add Then
e.Person.Group= Me
ElseIf e.ChangeType = Delete
e.Person.Group= Nothing
End If
End Sub

So after doing:
GroupA.Add(Person)
...the following is true:
PersonA.Group = GroupA.

The problem is that this creates an infinite loop. When Something is
added/removed to Group, the Person.Group setter is called. And when
the Person.Group setter is called, it triggers the Group ListChanged
event.

I am working on a messy solution with shared variables that allow the
ListChanged subs let the Person.Group setter know that it is being set
by the ListChanged event, and vice versa so they don't call each
other.
I am looking for a clean pattern. How would you solve this problem?
Oct 1 '08 #2

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

Similar topics

1
by: Prashanti | last post by:
Hi , I have built a windows application in c sharp which using the methods of COM Object. The application is working fine. Now need to make this application a package to deploy at client...
6
by: Daniel Bass | last post by:
The scenario: ------------- I've created a simple COM object according to a tutorial I found: http://www.csharphelp.com/archives/archive281.html It automatically creates a Type Library...
6
by: ian | last post by:
Hi All I have a DLL (nahd.dll) that has been supplied to me will a PBX phone system. According to the documentation it is to allow developers to write there own applications to monitor the...
6
by: Duncan Winn | last post by:
I have written an Ole Db provider. It seems to be registered in the Operating system to a degree, but not fully, i.e. I can access it from a client that I have written. But it does not appear in...
2
by: glenn | last post by:
I have written a COM Server in C# and its working perfectly. I am not ready to deploy to client computers to begin the real testing and am now wondering how to perform. The part that confuses me...
13
by: noone | last post by:
consider the following problem: You have a C style library and API that uses callbacks to implement functionality. Examples of this are X11 API, OpenGL/GLUT...The List goes on. The power of...
7
by: Chris Jewell | last post by:
Hi, I'm wondering what the best way of registering a data storage class with a data handler class is. At the moment I have two classes: class EpiCovars // Storage class { ....
1
by: shivkumar2004 | last post by:
Hi!, I am developing a chat system using vb.net in vs 2005. I am getting the following error while registering the events. error details: System.InvalidOperationException was unhandled...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
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
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...
1
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: 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...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.