Solved

Removing an item from an array.

Posted on 1998-09-26
3
143 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 58
Help on project with Soap 10 44
Making delphi communicate with a c# service 16 73
Delphi inherited method 6 42
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now