Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Deleting a record from an array

cjolleyscjolleys Member Posts: 14
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

  • zibadianzibadian Member Posts: 6,349
    : 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.
    :
    :
    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.
Sign In or Register to comment.