This is the class A
public class A
{
public delegate void Evento(object sender);
public event Evento Modified;
public static ArrayList LoadA()
{
SqlDataReader dr = readA();
ArrayList arrayTemp = new ArrayList();
while (dr.read())
arrayTemp.Add(A.LoadInstance(dr["idA"]);
return arrayTemp;
}
private static SqlDataReader ReadA()
{
SqlDataReader dr = Data.GetData("ReadA"); // Data is an object who can
acces to Sql server
return dr;
}
private static A LoadInstance()
{
SqlDataReader dr = Data.GetData("ReadA"); // Data is an object who can
acces to Sql server
A instance = new A();
A.property1 = dr["field"];
...
return instance;
}
public void Change()
{
// save changes in the data base
Modified(this);
}
}
In a form, where the user insert, delete, change and so on the data, I
insert the
instances of the object of type A in a arrayList in this way:
private void GetA()
{
arrayA = A.LoadA();
for (int i=0; i<arrayA.Count; i++)
{
((A)arrayA[i]).Modified += new A.Evento(frmA_Modified);
}
}
I hope you could understand it. Thank you very much.
"Jon Skeet [C# MVP]" <sk***@pobox.com> escribió en el mensaje
news:MP************************@msnews.microsoft.c om...
Alberto <al*****@nospam.com> wrote: I have a class A who send an event when an instance is modified.
So, I declared the event in this way:
public delegate void Evento(object sender);
public event Evento Modified;
To throw the event I wrote this sentence:
Modified(this);
I have a form who works with instances of the class A so I stored them in
a
arrayList. Every time I create an instance, I say it witch is the handler
of
the
event in this way:
((A)arrayA[i]).Modified +=
new A.Evento(frmA_Modified);
The problem is when the event is raised from the class A. The error says
that
there is a reference to an object not established as an object instance.
I don't understand what's happening. Could anyone help me?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too