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

Use of delegates

Hello everyone

I am perusing knowledge on the use of delegates; any assistance would be greatly appreciated. Lets take an example of a community of people, they are born, live a while, then die. The community would get notifications of birth and deaths, upon a death notice, they would bury the person. Below is my sample code, I am looking for a critique on its use and how I would go about doing this better. Thanks

Namespace bla

Public Delegate Sub Died(ByVal thisperson As Person
Public Delegate Sub Born(ByVal thisperson As Person

Public Class PopGe

Private PersonDied As blah.Die
Private PersonBorn As blah.Bor
Private col As Collection = New Collectio
Private col1 As Collection = New Collectio
Private WithEvents atimer As System.Timers.Time

Friend Sub Dieded(ByVal thisperson As Person
Debug.Write(thisperson.Index.ToString & ": has died" & vbCrLf
col1.Add(thisperson.Index, "Item:" & thisperson.Index.ToString
End Su

Friend Sub Borned(ByVal thisperson As Person
Debug.Write(thisperson.Index.ToString & ": was born" & vbCrLf
End Su

Public Sub New(

atimer = New System.Timers.Time
atimer.Interval =
atimer.Enabled = Tru

PersonBorn = New blah.Born(AddressOf Borned
PersonDied = New blah.Died(AddressOf Dieded

Dim i As Int3
For i = 1 To 10
'System.Threading.Thread.Sleep(50
col.Add(New Person(i, PersonBorn, PersonDied), "Item:" & i.ToString
Next

End Su

Private Sub atimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles atimer.Elapse
Dim i As Int3
Dim al As ArrayList = New ArrayLis
For Each i In col
al.Add(i
col.Remove("Item:" & i.ToString
'System.Threading.Thread.Sleep(50
Nex
For Each i In a
col1.Remove("Item:" & i.ToString
Nex
End Su
End Clas

Public Class Perso
Private _gender As Strin
Private WithEvents atimer As System.Timers.Time

Public ReadOnly Property Gender() As Strin
Ge
Return _gende
End Ge
End Propert

Private _age As Intege
Public ReadOnly Property Age() As Intege
Ge
Return _ag
End Ge
End Propert

Private _index As Int3
Friend ReadOnly Property Index() As Intege
Ge
Return _inde
End Ge
End Propert

Private _born As blah.Bor
Private _died As blah.Die
Public Sub New(ByVal Index As Int32, ByVal BornEvent As blah.Born, ByVal DiedEvent As blah.Died
_age = -
_born = BornEven
_died = DiedEven
_index = Inde
atimer = New System.Timers.Time
atimer.Interval = 50
atimer.Enabled = Tru
End Su

Protected Overrides Sub Finalize(
MyBase.Finalize(
Debug.Write(_index.ToString & ": removed" & vbCrLf
atimer.Enabled = Fals
End Su

Private Sub atimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles atimer.Elapse
'Assses life and deat
'or just get olde
atimer.Enabled = Fals
_age = _age +
If _age = 0 The
_born.Invoke(Me
atimer.Enabled = Tru
Exit Su
End I
If _age >= 100 The
_died.Invoke(Me
Els
atimer.Enabled = Tru
Exit Su
End I
End Su

End Clas

End Namespac

Jul 21 '05 #1
0 688

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

Similar topics

6
by: Jeffrey T. Smith | last post by:
Back when the new J2SE1.5 features were announced, there was a JavaLive community chat (http://java.sun.com/developer/community/chat/JavaLive/2003/jl0729.html) in which Neal Gafter explains the...
3
by: Sam | last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
4
by: AMDRIT | last post by:
I am trying to understand Delegates and where/when to use them. I can see one potential use of a delegate (on form closing, set the cancel property in the event arguments.) Does anyone have a...
6
by: =?Utf-8?B?Sko=?= | last post by:
I have a logger component that logs to multiple sources, ie textfile, eventlog etc. and I have two methods that depending on where I call up my logger comp. one of them will be called. For ex. if...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
6
by: =?Utf-8?B?T2xkQ2FEb2c=?= | last post by:
My question is regarding the use of delegates in C#. I see how .Net uses delegates to wire event handlers to events. It’s an object created by a single line of code by the system and that makes...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.