Solved

Removing an item from an array.

Posted on 1998-09-26
3
147 Views
Last Modified: 2010-04-06
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
Comment
Question by:Karma121397
3 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 50 total points
ID: 1340903
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
 

Author Comment

by:Karma121397
ID: 1340904
That was simple. =)

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

Thanks
0
 

Expert Comment

by:pramirezl
ID: 1340905
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question