Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Removing an item from an array.

Posted on 1998-09-26
3
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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