#1 2023-07-28 09:36:50

larand54
Member
Registered: 2018-12-25
Posts: 96

Examples on how to find an object in a dynamic array

I have a class that contains an array where I need to find a certain object in this array as I want to update this certain object.

I've tried to find examples of how to do this but still failed so my hope is that someone could have such an example to show how this could be done.

Thanks in advance!


Delphi-11, WIN10

Offline

#2 2023-07-28 11:59:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,260
Website

Re: Examples on how to find an object in a dynamic array

Why not just use a loop?

Offline

#3 2023-07-28 14:10:23

larand54
Member
Registered: 2018-12-25
Posts: 96

Re: Examples on how to find an object in a dynamic array

Ok, I've done that already but as the array can contain several hundreds of object in the worst case I thought that using a dynamic array could be more effective.
In this case, load and response time is not an issue but I like to be more effective and I can think of cases where this could be an issue.
And why not to be prepared?


Delphi-11, WIN10

Offline

#4 2023-07-29 07:39:35

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,260
Website

Re: Examples on how to find an object in a dynamic array

Searching in thousands of objects in memory if fast.
There is nothing else than a loop to do this.

The only fastest way may be to use an index, e.g. a hash table, but it would need more than a dynamic array.
You can do this with TDynArrayHasher if really needed in the future. But the data will remain in the dynamic array anyway.

Offline

Board footer

Powered by FluxBB