I am trying to convert a C or C++ code to Lazarus. I am using fpAlsa.
So far I have a working code to list the PCM devices except that at the end of the list I do not detect the end of the array and this generate a SIGSEV error.
Here is the original C code:
char **hints;
/* Enumerate sound devices */
int err = snd_device_name_hint(-1, "pcm", (void***)&hints);
if (err != 0)
return;//Error! Just return
char** n = hints;
while (*n != NULL) {
char *name = snd_device_name_get_hint(*n, "NAME");
if (name
!= NULL
&& 0 != strcmp("null", name
)) { //Copy name to another buffer and then free it
}
n++;
}//End of while
//Free hint buffer too
snd_device_name_free_hint((void**)hints);
My translation is this:
Procedure ListDevices ;
Var Hints : PPPointer ;
err,i : integer;
n : PPointer ;
Name,Desc,IOID :Pchar ;
begin
new(Hints);
err := snd_device_name_hint(-1,'pcm', Hints) ;
if err <> 0 then begin
ShowMessage('Error accessing devices, Error:'+ inttoStr(err));
exit ;
end;
showMessage('No Error in hint');
n := Hints^ ;
try
try
while (n <> nil) do begin
name := snd_device_name_get_hint(n^,Pchar('NAME')) ;
desc := snd_device_name_get_hint(n^,'DESC') ;
IOID := snd_device_name_get_hint(n^,'IOID') ;
If IOID <> '' then
if IOID = 'Input' then
Showmessage(string(Name) + ' | ' + String(desc) + ' | ' + string(IOID)) ;
Inc(N) ;
//If snd_device_name_get_hint(n^^,Pchar('NAME')) ='' then break;
end;
except
on E: Exception do
ShowMessage(E.Message);
end;
finally
showmessage('end of List') ;
end;
err := snd_device_name_free_hint (hints^) ;
if err <> 0 then begin
ShowMessage('Error freeing hints, Error:'+ inttoStr(err));
exit ;
end;
showMessage('No Error in free');
end;
The types from fpAlsa are :
PPointer = ^Pointer;
PPPointer = ^PPointer;
My problem is that while (n <> nil) is never detected.
Is there a mean to detect the end of this "C" array of pointer?
Thanks.