Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-05

TFPHashList and nil pointers

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Serguei TARASSOV

Hello,

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;
uses
   Contnrs;
var
   List: TFPHashList;
begin
   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.Free;
end.

Output:
List count: 2
Index of Name1: 0
Index of Name2: -1

regards,
Serguei

Reply by email

Michael Van Canneyt
to Serguei TARASSOV
Serguei TARASSOV wrote 29 lines
Hello, 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; uses Contnrs; var List: TFPHashList; begin 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.Free; end. Output: List count: 2 Index of Name1: 0 Index of Name2: -1

It is by design.

Michael.

Reply by email

waldo kitty
to Michael Van Canneyt
Michael Van Canneyt wrote 34 lines
On Tue, 19 May 2015, Serguei TARASSOV wrote: > Hello, > > 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; > > uses > Contnrs; > > var > List: TFPHashList; > begin > 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.Free; > end. > > Output: > 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?

NOTE: No off-list assistance is given without prior approval. Please *keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

Michael Van Canneyt
to waldo kitty
waldo kitty wrote 38 lines
On 05/20/2015 07:11 AM, Michael Van Canneyt wrote: > > > On Tue, 19 May 2015, Serguei TARASSOV wrote: > >> Hello, >> >> 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; >> >> uses >> Contnrs; >> >> var >> List: TFPHashList; >> begin >> 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.Free; >> end. >> >> Output: >> 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.

Michael.

Reply by email