Recent

Author Topic: search in TFPGObjectlist  (Read 2070 times)

paweld

  • Hero Member
  • *****
  • Posts: 1217
Re: search in TFPGObjectlist
« Reply #30 on: August 12, 2024, 10:43:57 am »
IndexOf won't work, because you're always creating a new object (based on data from another source), so it will never be in the list of objects.
Unfortunately, you'll have to resort to a more complicated solution if you want a quick solution, or you'll have to check the entire list element by element to see if an object with that ID exists (slower).
In fact, the solution with TFPGMap is a bit more complicated, but in the end you create the class once and can use it later in other projects if you extract it into a separate entity.

As for Generics.Collection, it works without a problem in ObjFpc mode (see my example), you just need to specialize the types - but BinarySearch won't return results for the same reason as IndexOf.
Best regards / Pozdrawiam
paweld

JohnKuiper

  • New member
  • *
  • Posts: 7
Re: search in TFPGObjectlist
« Reply #31 on: August 12, 2024, 11:34:38 am »
What is the reason to use TFPGObjectlist.Indexof(T).

@paweld
I use system.generics a lot in my Delphi applications' :D
But a few years now the whole application is build on FGL (and it works perfectly)

 

TinyPortal © 2005-2018