Forum > FPC development
RTL-Generics question/suggestion regarding TCustomList<T>.ToArray
(1/1)
SlightlyOutOfPhase:
.
Thaddy:
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.
Thaddy:
--- Quote from: SlightlyOutOfPhase on November 15, 2016, 04:07:08 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.
--- End quote ---
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.
hnb:
--- Quote from: SlightlyOutOfPhase on November 20, 2016, 12:47:19 am ---So many more views than when I last posted, but no one has any input?
--- End quote ---
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.
marcov:
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.
Navigation
[0] Message Index