Well, I'm trying to use this procedure to delete array items:
Before I declare in Type:
TStringArray = array of string;
In public:
filestoadd : TStringArray;
And 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;
I'm trying to use it like this:
DeleteElement(filestoadd, ListBox1.ItemIndex)
But when I use it, it gives access violation 0040989C. The error line is exactly the line that calls the function:
First chance exception at $ 004098C8. Exception class $ C0000005 with message 'access violation at 0x004098c8: read of address 0xfffffff'. Process ExeGenerator.exe (5808)
How can I fix this?