• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Removing an item from an array.

I want to be able to remove a record from a dynamic array. Say I have 10 items in the array and I want to remove item 5... how would I do it?

Thanks.
0
Karma121397
Asked:
Karma121397
1 Solution
 
MotazCommented:
What did you mean by dynamic array ?

If you have normal array of bytes you can remove item number 5 by this procedue :

ArraySize:=10;

for i:=5 to ArraySize-1 do
  MyArray[i]:=MyArray[i+1];

Dec(ArraySize);

Motaz.
motaz1@yahoo.com
0
 
Karma121397Author Commented:
That was simple. =)

I'm using dynamic arrays which were introduced in Delphi 4.0, but that shouldn't matter anyway.

Thanks
0
 
pramirezlCommented:
If you are using arrays with variant, you can use the following funtion:

VarArrayRedim()

This function allows you to change the size of the array.

Example:

var
 A: Variant;
 I: Integer;
begin
 A := VarArrayCreate([0, 4], varOleStr);
 for I := 0 to 4 do A[I] := 'Initial';
 ...
 VarArrayRedim(A, 9);
 for I := 5 to 9 do A[I] := 'Additional';
 ...
end;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now