Recent

Author Topic: RTL-Generics question/suggestion regarding TCustomList<T>.ToArray  (Read 5795 times)

SlightlyOutOfPhase

  • New member
  • *
  • Posts: 8
.
« Last Edit: February 21, 2020, 10:42:00 pm by SlightlyOutOfPhase »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: RTL-Generics question/suggestion regarding TCustomList<T>.ToArray
« Reply #1 on: November 13, 2016, 07:22:12 am »
Instead of modifying an existing abstract class, you should derive a new class if you need that functionality.

Btw: it is of course only faster if the array is accessed sequentially. You loose the enumerator support.
« Last Edit: November 13, 2016, 07:33:54 am by Thaddy »
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: RTL-Generics question/suggestion regarding TCustomList<T>.ToArray
« Reply #2 on: November 15, 2016, 06:05:21 pm »
Well yes, it's certainly true that I could derive a new class. I was merely suggesting to add it to the TCustomList<T> class specifically since that is the class that the major commonly used Generic list classes (TList<T>, TObjectList<T>, e.t.c) descend from, so if it were added at that level they would all have it by default.
I knew that. I still stick to my answer. Because of the same reasoning.
In addition: if you need that kind of array access you chose the wrong structure.
But that is merely theory. I appreciate you want to see it in the base class.
I think that is wrong, but it won't hurt much for average users.
« Last Edit: November 15, 2016, 06:08:26 pm by Thaddy »
Specialize a type, not a var.

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: RTL-Generics question/suggestion regarding TCustomList<T>.ToArray
« Reply #3 on: November 24, 2016, 01:53:34 pm »
So many more views than when I last posted, but no one has any input?

TList has FItems in protected section. You can create "class helper" to expose FItems or you can create descendant class from TList. Situation is not bad :) FItems in Delphi is declared in private section.

If you really like to have AsArray please create bug report on bugtracker.
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: RTL-Generics question/suggestion regarding TCustomList<T>.ToArray
« Reply #4 on: November 24, 2016, 02:49:17 pm »
Download the code in the  http://forum.lazarus.freepascal.org/index.php/topic,30556.msg194484.html#msg194484 topic, and look at the units glhelper/gloverlayhelp

Basically I exported the pointer value and the elementsize from my generic class.

 

TinyPortal © 2005-2018