Recent

Author Topic: THashedStringList - do we have it still?  (Read 482 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1095
THashedStringList - do we have it still?
« on: April 17, 2025, 07:08:28 pm »
This is done
- a method calls a function
- this function does a query with a unknown count of results and returns them at the moment in a THashedStringList.
Each "hit" has naturally a primary key, which is known by the function
- the calling method writes the function's results (=the THasedStringList) into a TListView
- the user clicks one line of the TListView and triggers the ListView's click-Event.

How to get the primary key into the ListView's click-Event?!

My idea was, that it shall be saved in the returned HashStringList.
Unfortunately I neither know, how to key in the primary keys as values.
Nor do I know, how to grab those values, after having added the words to the TListView.

In other words:
I need a way to get the primary key into the click event of the TListView.

I am thankful for any syntax, how to read and write a HasehdStringList.
As well as better ways to do it.


In the meanwhile I found a better documenation.
https://www.freepascal.org/docs-html/fcl/inifiles/thashedstringlist.indexof.html

« Last Edit: April 18, 2025, 11:21:36 am by Nicole »

cdbc

  • Hero Member
  • *****
  • Posts: 2127
    • http://www.cdbc.dk
Re: THashedStringList - do we have it still?
« Reply #1 on: April 17, 2025, 07:22:41 pm »
Hi
Hmmm, there's always the 'Data' property of 'TListItem', you can use, it's a pointer so you can put anything in it. It's easily accessible when clicked...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Nicole

  • Hero Member
  • *****
  • Posts: 1095
Re: THashedStringList - do we have it still?
« Reply #2 on: April 17, 2025, 07:44:01 pm »
The pointer won't work stable. The database query result is nothing, which I dare to trust, the pointer will point there after a while still.

cdbc

  • Hero Member
  • *****
  • Posts: 2127
    • http://www.cdbc.dk
Re: THashedStringList - do we have it still?
« Reply #3 on: April 17, 2025, 07:49:04 pm »
Hi
Where should it run off to...?  It doesn't know anybody...  :D ;D ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11139
  • Debugger - SynEdit - and more
    • wiki
Re: THashedStringList - do we have it still?
« Reply #4 on: April 17, 2025, 07:51:23 pm »
Create your own list from a generic list... Then you can store any data you need, as long as you need.

In the ListView, in the "Data" just store the index of the entry in the created list.  (Or store "index + 1", so you can have zero/nil as detectable "not set")

Nicole

  • Hero Member
  • *****
  • Posts: 1095
Re: THashedStringList - do we have it still?
« Reply #5 on: April 17, 2025, 08:14:19 pm »
How to?

The first step is:
set the pk in the function, this should be:
result.     ????????   :=primaryKey;

second
get it to the ListView1 by
ListView1.???????????  :=HashedStrinList1.???

third
read it in the ListView1ClickEvent
pk:=ListView1.?????????

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11139
  • Debugger - SynEdit - and more
    • wiki
Re: THashedStringList - do we have it still?
« Reply #6 on: April 17, 2025, 08:32:53 pm »
Without running syntax checks...

Code: Pascal  [Select][+][-]
  1. uses fgl;
  2. {$modeswitch advancedrecords}
  3. type
  4.   TMyFooData = record
  5.     PKey: TPKeyType; // int / string/ ....
  6.     Text: string;
  7.     // ... other data
  8.  
  9.     class operator = (Item1, Item2: TMyFooData): Boolean;
  10.   end;
  11.  
  12.   TMyList = specialize TFPGList<TMyFooData>;
  13.  
  14. ////// for each item
  15. var
  16.   Data: TMyFooData;
  17.   Lst: TMyList;
  18. begin
  19.   Data.PKey := ...
  20.   Data.Text := the_text;
  21.   idx : Lst.Add(Data);
  22.   ListView.AddObject(the_text, TObject(PtrUint(idx)));
  23.  
  24.  
« Last Edit: April 17, 2025, 08:35:33 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11139
  • Debugger - SynEdit - and more
    • wiki
Re: THashedStringList - do we have it still?
« Reply #7 on: April 17, 2025, 08:39:23 pm »
In the click-event you should be able to get the itemindex of the clicked item.

and then (something like).
Code: Pascal  [Select][+][-]
  1. idx := ptruint(ListView.items.objects[itemindex])

I am not sure if the property is "items". But afaik/iirc there is an interface to store/retriev objects with each displayed item.

paule32

  • Sr. Member
  • ****
  • Posts: 441
Re: THashedStringList - do we have it still?
« Reply #8 on: April 17, 2025, 08:40:55 pm »
seems that Nicole would like do some documenting stuff ?
is'n it ?

get in touch with me to extend the people on a project of me (us).
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Thaddy

  • Hero Member
  • *****
  • Posts: 16937
  • Ceterum censeo Trump esse delendam
Re: THashedStringList - do we have it still?
« Reply #9 on: April 18, 2025, 09:53:43 am »
The items property is default afaik so you can notationally skip it.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018