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