[fpc-pascal] TFPHashList and nil pointers
Michael Van Canneyt
michael at freepascal.org
Wed May 20 14:20:43 CEST 2015
On Wed, 20 May 2015, waldo kitty wrote:
> On 05/20/2015 07:11 AM, Michael Van Canneyt wrote:
>> On Tue, 19 May 2015, Serguei TARASSOV wrote:
>>> Is it normal that TFPHashList cannot find an item by name if the pointer
>>> is nil?
>>> However, the item is stored in the list.
>>> FPC 2.6.4, both Windows and Linux versions.
>>> program project1;
>>> List: TFPHashList;
>>> List := TFPHashList.Create;
>>> List.Add('Name1', List);
>>> List.Add('Name2', nil);
>>> writeln('List count: ', List.Count);
>>> writeln('Index of Name1: ', List.FindIndexOf('Name1'));
>>> writeln('Index of Name2: ', List.FindIndexOf('Name2'));
>>> List count: 2
>>> Index of Name1: 0
>>> Index of Name2: -1
>> It is by design.
> how do you find and update that item and its pointer?
I suspect you don't.
TFPHashList was copied from the compiler sources.
As such, it's very much a one-shot list to be filled quickly with one time data, then not to be manipulated any more.
For frequent updates and manipulations, you can better use the TFPDataHashTable.
It is slightly slower, but more all-round.
More information about the fpc-pascal