Bom, estou tentando usar esta Procedure para apagar items de array:
Antes declarei em Type:
TStringArray = array of string;
Em public:
filestoadd : TStringArray;
E no create:
for x:=0 to 5 do begin
SetLength(filestoadd, x);
filestoadd[x] := IntToStr(x)+'test';
end;
A procedure:
procedure DeleteElement(anArray:TStringArray;const aPosition:integer);
var
lg, j : integer;
begin
lg := length(anArray);
if Length(anArray) < aPosition then
exit;
if aPosition = lg-1 then
exit
else if aPosition = lg-1 then begin //if is the last element
//if TSomeType is a TObject descendant don't forget to free it
//for example anArray[aPosition].free;
Setlength(anArray, lg -1);
exit;
end;
for j := aPosition to lg-2 do//we move all elements from aPosition+1 left...
anArray[j] := anArray[j+1];//...with a position
SetLength(anArray, lg-1);//now we have one element less
//that's all...
end;
Estou tentando usar assim:
DeleteElement(filestoadd, ListBox1.ItemIndex)
Mas quando uso, dá acess violation 0040989C. A linha de erro é exatamente a linha que chama a function:
First chance exception at $004098C8. Exception class $C0000005 with message 'access violation at 0x004098c8: read of address 0xfffffffc'. Process ExeGenerator.exe (5808)
Como posso ajeitar isso?