Scott Kellish (@Work) wrote:

> Stephen,
> The instance of the object still exists despite not explicitly being
> assigned to a variable (local or global). From the limited code provided, it
> seems like all of the work is being done within the context of the with
> statement which is perfectly legitimate. We don't know what the OnEndPlay
> property looks like, but it would typically be something like:
> 
> TNotifyEvent = procedure(Sender: TObject) of object;
> 
> So that the called event handler gets an pointer to the object which could
> then be used to free it.

You're 100% correct, I overlooked the assignment of 
OnEndEventPlay to the OnEndPlay handler in the WITH statement 
(mea culpa).

> I would also urge some caution in freeing objects inside event handlers like
> David is doing. You have to absolutely sure that the code that calls your
> event handler, where you then free the object, does not do further
> processing after you return, because the object is effectively dead and
> memory released at that point.

Absolutely, you're basically pulling the rug out from under 
yourself like that.

> Back to the original problem though, if David is looking to somehow
> manipulate the instance outside of the PlaySoundCue method then I certainly
> agree that a hard reference to it needs to be held somewhere. From the code,
> it looks like the dsMixer object is the parent of the new TcbDSMixerChannel
> instance. Perhaps its easy enough just to iterate over the dsMixer
> Components collection to find the object. There's not enough information
> provided to speculate further.

Agreed.

Stephen Posey
[EMAIL PROTECTED]

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to