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. 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. 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. Thanks, Scott I am always willing to learn. I do not, however, always enjoy being taught. - Sir Winston Leonard Spencer Churchill __________________________________________ SoftSystem Solutions, LLC 18 Ridge Road Clark, New Jersey 07066 USA Scott Kellish, Owner Tel. +01 732 382 1873 Fax: +01 732 382 1873 Mobile: +01 732 261-5856 e-mail: [EMAIL PROTECTED] __________________________________________ ----- Original Message ----- From: "Stephen Posey" <[EMAIL PROTECTED]> To: "Borland's Delphi Discussion List" <[email protected]> Sent: Thursday, September 29, 2005 10:02 AM Subject: Re: Referencing a component > David Duffy wrote: > > I'm only into Delphi in a small way. (D7 professional) > > Normally I plonk components on forms and when I need > > to reference them I just use the component name. But... > > > > I'm making a small audio player (freeware) and I am > > creating the audio channels as required as there are > > multiple sounds to be played at once sometimes. > > > > I'm creating the instance ok (I think) and starting it > > playing, but can't get how to adjust it while it's in > > use. (playing) I'm freeing the instance in the OnEndPlay > > handler and that seem to work out ok. Help please? :-) > > > > > > function TfmMain.PlaySoundCue(CueRow: integer):boolean; > > var > > SoundFilename: TFilename; > > begin > > Result := False; > > SoundFilename := GrCueList.Cells[6,CueRow]; > > if FileExists(SoundFilename) then begin > > with TcbDSMixerChannel.Create(dsMixer) do begin > > FileName := SoundFilename; > > Volume := -(3000-(StrToInt(GrCueList.Cells[4,CueRow])*30)); > > Pan := StrToInt(GrCueList.Cells[5,CueRow])*30; > > Tag := CueRow; > > OnEndPlay := OnEndEventPlay; > > Name := 'Channel' + IntToStr(CueRow); > > Play; > > Result := True; > > end; > > end; > > end; > > Using the WITH statement like this, you've created an "anonymous" > instance of the component, so there's no way to refer to it > outside the WITH statement (which makes me curious how you're > referring to the instance to "[free] the instance in the > OnEndPlay handler"). > > In order to have access to an instance like this in other places, > you need to provide a global reference, which is most easily done > by adding an instance variable of the appropriate type as a field > of the form, something like: > > TfrmMain = class(TForm) > ... > public > MixerChannel: TcbDSMixerChannel; > PlaySoundCue(CueRow: integer):boolean; > end; > > Then in your method: > > function TfmMain.PlaySoundCue(CueRow: integer):boolean; > var > SoundFilename: TFilename; > begin > Result := False; > SoundFilename := GrCueList.Cells[6,CueRow]; > if FileExists(SoundFilename) then begin > MixerChannel := TcbDSMixerChannel.Create(dsMixer); > with MixerChannel do begin > ... > > Now you can refer to MixerChannel anywhere in your form code. > > When you're ready to release the instance, just do: > > MixerChannel.Free; > > Does that make sense? > > HTH > > Stephen Posey > [EMAIL PROTECTED] > > _______________________________________________ > Delphi mailing list -> [email protected] > http://www.elists.org/mailman/listinfo/delphi > CONFIDENTIALITY NOTICE: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of this message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error and permanently delete this message and any attachments. Thank you. _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

