How do you delete a record from an array?? Or a stringgrid?? I have a file with about 20 records in it and I want to delete the one i have selected (using this code):
if (edit2.text)=(namesarray[g,2]) then
namesarray[g,1]:=namesarray[g+1,1];
namesarray[g,2]:=namesarray[g+1,2];
namesarray[g,3]:=namesarray[g+1,3];
namesarray[g,4]:=namesarray[g+1,4];
but this doesn't work because it duplicates the record that appears below it.
Comments
: if (edit2.text)=(namesarray[g,2]) then
: namesarray[g,1]:=namesarray[g+1,1];
: namesarray[g,2]:=namesarray[g+1,2];
: namesarray[g,3]:=namesarray[g+1,3];
: namesarray[g,4]:=namesarray[g+1,4];
: but this doesn't work because it duplicates the record that appears below it.
:
:
You are on the right track. For an array you need to move the record to be deleted to the end of the record, as you have done above. Then you can use SetLength() to shorten the array.
Another way it so copy() parts of the array into a new array.
In case of a stringgrid, you can access the rows and columns using the appropriate property. These are TStrings, which means they have a Delete() method.