This is all a lot simpler and less error-prone using AppGameKit for Pascal.
Here's a complete unit to implement what you have, without comments, which will be below.
unit USoundManage;
interface
Uses classes, sysutils,AGK;
Type TSoundManager = class(TagkObject)
Private
SoundList : TStringlist;
public
Constructor Create(AOwner:TagkObject);
Destructor Destroy;
procedure Clear;
function LoadSound(Name : string):boolean;
function PlaySoundByName(Name : string; looped : boolean; Volume : integer):boolean;
end;
implementation
{ TSoundManager }
constructor TSoundManager.Create;
begin
SoundList := TStringList.Create;
SoundList.Sorted := true;
SoundList.Duplicates := dupIgnore;
end;
destructor TSoundManager.Destroy;
begin
// don't need to do anything!
// it's automatic
end;
function TSoundManager.LoadSound(Name: string):boolean;
var S : TAgkSound;
path : ansistring;
begin
path := Format('/Sounds/%s.ogg',[Name]);
result := FileExists(path);
if result then
begin
S := TAgkSound.Create(self,path);
if assigned(s) then
begin
result := true;
SoundList.AddObject(Name,S);
end;
end;
end;
function TSoundManager.PlaySoundByName(Name: string; looped: boolean; Volume : integer): boolean;
var i : integer;
begin
i := SoundList.IndexOf(Name);
result := i>=0;
if i > 0 then TagkSound(SoundList.Objects[i]).Play(Volume,looped);
end;
procedure TSoundManager.Clear;
var i : integer;
begin
if soundlist.Count=0 then exit;
for i := 0 to Pred(Soundlist.Count) do TagkSound(SoundList.Objects[i]).Free;
SoundList.Clear;
end;
end.
Because there is (in the original) only the need for a name, a StringList is fine. It has the possibility for each entry in the list to have a string and a pointer.
If you wanted a more structured type then you would simply create that instead of the TagkSound and add it to the list in the same way. The object itself would have a pointer to an TagkSound object.
Instead of using indices here were are using object pointers. It is entirely possible to do it with an index if you wish, but it complicates things unnecessarily.
Usage is like this:
var MySoundManager : TSoundManager;
MySoundManager := TSoundManager.Create(self);
....
MySoundManager.LoadSound('Gunshot1');
MySoundManager.PlaySoundByName('Gunshot1', false, 100);
-- Jim - When is there going to be a release?