var
SourceArray: Array of TSourceRec;
...
I can't figure out how to remove a specific entry at index "i". For example,
SourceArray.Delete(i)/RemoveItem(i) or something of the sort. I just want to
delete the entry at position "i" in the array. Is it possible?!
Thanks much in advance!
Jeff Guillaume
ColdFusion Developer
Direct Dial: (877) 399-9108
Direct Fax: (419) 793-2382
StoneAge.com: (800) STONEAGE x 280
E-mail: jguil...@stoneage.com
Jeff, Have you tried the obvious. Regards, JohnH
procedure Delete(var SourceArray: Array of TSourceRec; i: integer);
var j: integer;
begin
if (i<0) or (i>=length(SourceArray))
then EXIT;
For j := i to length(SourceArray)-2 do
SourceArray[j] := SourceArray[j+1];
SetLength(SourceArray,length(SourceArray)-1);
end;
UNTESTED!
I just can't decide whether to switch to TList now, or just hack my way
around for solutions as they come up. Suggestions? :)
"John Herbster" <jo...@petronworld.com> wrote in message
news:3b55e49d$1_2@dnews...
Jeff, Here are a few differences:
A TList and its elements require Create and Free. TL's are good for
insertions and deletions as long as list is not too large. TList
requires type casting of the element pointers.
Dynamic arrays require just SetLength() and no cleanup. DA's are
even slower than TL's for insertions and deletions. For plain
access, DA's require no type casting.
And then there are also queues and hash tables.
Regards, JohnH
Delete( SourceArray, i, 1 );
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.
>Jeff wrote
>>> I just can't decide whether to switch to TList now, or just hack
>my way around for solutions as they come up. Suggestions? :)
>A TList and its elements require Create and Free. TL's are good for
>insertions and deletions as long as list is not too large. TList
>requires type casting of the element pointers.
>
>Dynamic arrays require just SetLength() and no cleanup. DA's are
>even slower than TL's for insertions and deletions. For plain
>access, DA's require no type casting.
Actually, TLists are a static array of pointers which is probably
why they are a little quicker than dynamic arrays.
TPointerList = array[0..MaxListSize-1] of Pointer;
Another thing he could do to handle deletions is to add a delete
flag. Simply flag the item for deletion and cleanup when needed.
If I remember correctly, this is how DBase used to handle the
problem. If it saw a deletion flag, it skipped the entry and packed
the records on exit..
John McTaggart
Peter, Is this a D6 thing? Regards, JohnH
You sent this same question to a mailing list, and I answered it for you
this afternoon--check your e-mail.
--Rob
May be that D6 will allow that, but my post was more the result of
doing newsgroup work when i should have been asleep <g>. Doesn't work
in <= D5, of course. Sorry for the confusion.
Peter, You have pulled so many useful rabbits out of the hat that I
thought that this was just another one -- till I tried it. Best
regards and don't wear yourself out. JohnH
> I just can't decide whether to switch to TList now, or just hack my way
> around for solutions as they come up. Suggestions? :)
I am a little biased, as I have never been too thrilled with dynamic arrays
since I often need to moving large chunks of data quickly. IMHO, the
dynamic array idea in its current form is good for infrequently changed
numeric or simple records, but it still lacks manipulative power to make it
a serious contender for what I need to do (too bad the overload procedure
for string like Delete does not exist, as this would have been really cool.
Delphi 7?).
Given that, with the complicated record structure you have I would probably
go with a TList if you might think that any time in the future you will want
to delete, insert, sort, or even pack records and you expect to have >
10,000 records. Anything below that number, then just the "obvious" option
already mentioned is just fine. If you use TList, you will have to use
New() and Dispose() your record pointers as you add and delete them (and
when the list if freed). And for more to think about, you can also change
your record to an object and use TObjectList as this can handle memory
management for you.
Finally, if you really want to get your hand dirty, you can create your own
dynamic array type for your record structure. That is somewhat more
complicated but very useful for fast memory management.
Cheers,
Kevin