Solved

Removing an item from an array.

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

Technology Partners: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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