Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using events in array of objects 1

Status
Not open for further replies.

Slippie

Programmer
Jan 17, 2006
6
ZA
I have a problem using events occuring in a object in the Mainform.

I've created an array of objects with the name TUser.

Inside this object is an event with the name OnStreamReceivedFromClient which is of the type EventOnStreamReceived which is a procedure passing a TMemoryStream.

Now I've tried casting that event to an event in the MainForm doing the following:

private:
Users : Array of TUser;

implementation

SetLength(Users,Length(Users)+1);
Users[Length(Users)-1] := TUser.Create(Self,ListViewUsers, APort);
Users[Length(Users)-1].OnStreamReceivedFromClient := EventDirectStream;

The implementation part is called if a new user is created.

On the event occurence I get the error :
Access Violation at address 00404344 in module 'Chat.exe' . Read of
address 008D5B40.

Is there any way to pass an event occurence from inside an array of objects or do I have to start polling to see if the event occured?
 
Code:
  MyArray[i] := TMyObject.Create(...);
  MyArray[i].MyEvent := MyEventHandler;

The idea is right, I use it a lot. You have some other problems. Give me some time to check the dinarray expansion.

BRB.
buho (A).
 
The expansion code is ok. Post some more code and tell us exactly where the AV is thrown.

buho (A).
 
Thanks buho, the problem wasn't with the event handler, but rather in a unit I wrote to handle strings in streams which was called in the handler.

I still haven't figured out the problem, but I'll post the problem in a new thread.
 
Never put an object into a public array or structure until that object is fully initialized and ready to go.

Create the object, set up its event-handling properties, then add it to the list.

Be mindful of "owner." Owners destroy things when they go away. Objects don't have to have owners; they can be nil.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top