BigBuffer : array of Char;
e di fare
i := (256 * Ord(Buffer[9]) + Ord(Buffer[10]));
SetLength(BigBuffer, i+1);
FS.Seek(0, soFromBeginning);
FS.Read(BigBuffer, i) ;
Ebbene dopo questo ogni volta che provo ad accedere ad un valore
BigBuffer[x] incappo in un errore tipico di quando si esce dal campo di
valori poissibili, e accade acnhe andando in BigBuffer[2] !!!
Come mai, visto che la mia procedura funziona a meraviglia usando un array
di dimensione predefinita?
> i := (256 * Ord(Buffer[9]) + Ord(Buffer[10]));
> SetLength(BigBuffer, i+1);
>
> FS.Seek(0, soFromBeginning);
> FS.Read(BigBuffer, i) ;
>
> Ebbene dopo questo ogni volta che provo ad accedere ad un valore
> BigBuffer[x] incappo in un errore tipico di quando si esce dal campo di
> valori poissibili, e accade acnhe andando in BigBuffer[2] !!!
Può essere che i valga 0 e quindi non viene allocato proprio niente.
Hai provato a fare il debug e vedere il valore di i e di BigBuffer?
Appena faccio
Temp := (BigBuffer[i]) +
(BigBuffer[i+1]) +
(BigBuffer[i+2]) +
(BigBuffer[i+3]);
da subito errore!
"Balbar" <...@...> ha scritto nel messaggio
news:iNA3a.18822$%p6.15...@news.edisontel.com...
Ma che valori ha in questo caso la variabile i quando vai a calcolare
BigBuffer?
Forse dovresti provare a postare del codice un po' più "completo" da quando
inizializzi
BigBuffer fino al primo punto in cui ti da errore. Altrimenti è difficile
capirè perchè non
vada.
function Mp3GetId3V2Ver(NomeFile: String): Mp3Id3V2Ver;
var
FS : TFileStream;
Buffer : array [1..128] of Char;
BigBuffer : array of Char;
MyMp3Id3V2Ver : Mp3Id3V2Ver;
i, Index, RightIndex : Integer;
Temp : String[4];
begin
FS := TFileStream.Create(NomeFile, fmOpenRead or fmShareDenyWrite);
FS.Seek(0, soFromBeginning);
FS.Read(Buffer, 128);
Result.TagExists := False;
Result.Id3Ver := '';
with Result do begin
try
if Copy(Buffer, 1, 3) = 'ID3' then begin
TagExists := True;
Id3Ver := '2.' + IntToStr(Ord(Buffer[4]));
i := (256 * Ord(Buffer[9]) + Ord(Buffer[10])); //va sempre, l'ho
controllato! //ShowMessage('"'+IntToStr(i)+'"');
SetLength(BigBuffer, i);//(256 * Ord(Buffer[9]) + Ord(Buffer[10])) +
1);
FS.Seek(0, soFromBeginning);
FS.Read(BigBuffer, i) ;
i := 0;
RightIndex := 0;
repeat
i := i + 1;
Temp := (BigBuffer[i]) +
(BigBuffer[i+1]) +
(BigBuffer[i+2]) +
(BigBuffer[i+3]);
for Index := 0 to 63 do begin //63 dipende dal max dell'array
FramesID
if Temp = FramesId[Index] then begin
RightIndex := i;
Break;
end;
end;
until (RightIndex > 0);
ShowMessage(IntToStr(RightIndex));
end;
finally
FS.Free;
end;
end;
end;
"Balbar" <...@...> ha scritto nel messaggio
news:VrK3a.18890$%p6.15...@news.edisontel.com...
>
> > Certo!
> > i := (256 * Ord(Buffer[9]) + Ord(Buffer[10]));
> > e ho sempre controllato che Buffer contenga dati validi!
> >
> > Appena faccio
> >
> > Temp := (BigBuffer[i]) +
> > (BigBuffer[i+1]) +
> > (BigBuffer[i+2]) +
> > (BigBuffer[i+3]);
> >
> > da subito errore!
>
> Ma che valori ha in questo caso la variabile i quando vai a calcolare
> BigBuffer?
> Forse dovresti provare a postare del codice un po' piů "completo" da
quando
> inizializzi
> BigBuffer fino al primo punto in cui ti da errore. Altrimenti č difficile
> capirč perchč non
> vada.
>
>
Prova con questa:
function Mp3GetId3V2Ver(NomeFile: String): Mp3Id3V2Ver;
var
FS : TFileStream;
Buffer : array [1..128] of Char;
BigBuffer : PByteArray;
MyMp3Id3V2Ver : Mp3Id3V2Ver;
Dim, i, Index, RightIndex : Integer;
Temp : string[4];
begin
FS := TFileStream.Create(NomeFile, fmOpenRead or fmShareDenyWrite);
try
FS.Seek(0, soFromBeginning);
FS.Read(Buffer, 128);
Result.TagExists := False;
Result.Id3Ver := '';
with Result do begin
if Copy(Buffer, 1, 3) = 'ID3' then
begin
TagExists := True;
Id3Ver := '2.' + IntToStr(Ord(Buffer[4]));
Dim := (256 * Ord(Buffer[9]) + Ord(Buffer[10])); //va sempre, l'ho
controllato! //ShowMessage('"'+IntToStr(i)+'"');
GetMem(BigBuffer, Dim);//(256 * Ord(Buffer[9]) + Ord(Buffer[10])) +
1);
FS.Seek(0, soFromBeginning);
FS.Read(BigBuffer, i) ;
i := 0;
RightIndex := 0;
repeat
Temp:=Chr(BigBuffer[i])+
Chr(BigBuffer[i+1])+
Chr(BigBuffer[i+2])+
Chr(BigBuffer[i+3]);
for Index := 0 to 63 do begin //63 dipende dal max dell'array
FramesID
if Temp = FramesId[Index] then begin
RightIndex := i;
Break;
end;
end;
i := i + 1;
until (RightIndex > 0) or (i>Dim-4);
ShowMessage(IntToStr(RightIndex));
FreeMem(BigBuffer,Dim);
end;
end;
finally
FS.Free;
end;
end;
Ciao
Giorgio
"Giorgio" <nonne...@ciao.it> ha scritto nel messaggio
news:44U3a.253893$AA2.9...@news2.tin.it...
> provo subito!
facendolo seguire da quasi 5 k di testo dei messaggi precedenti.
Che dire?
http://groups.google.com/groups?oi=djq&ic=1&selm=an_628820033
e
*plonk*
Saluti
Paolo Arosio