Recent

Author Topic: IStringList...  (Read 11477 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: IStringList...
« Reply #30 on: August 20, 2024, 04:57:32 pm »
Just add datalength for data.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #31 on: August 20, 2024, 05:57:50 pm »
Hi Thaddy
The 'aData' / 'UserData' is thought to be used like this:
Code: Pascal  [Select][+][-]
  1. function TcsuModelMain.GetStaticTexts(const aSection: string; out aTarget: integer): IStringList;
  2. begin
  3.   if aSection = '' then exit(nil);
  4.   fSection:= '['+aSection+']'; fSecId:= IndexText(fSection,sects); // iterator-search
  5.   if fTextCache.Count = 0 then begin
  6.     fPresenter.Provider.NotifySubscribers(prStatus,nil,Str2Pch('(!) ERROR: Could NOT retrieve static texts!'));
  7.     exit(nil); /// maybe we should just comment this line and return an empty list, avoid AVs ///
  8.   end;
  9.   Result:= CreateStrList;
  10.   fTextCache.ForEach(@DoEach,Result);{ iterate over the source-list calling 'doeach' for each item }
  11.   aTarget:= fSecId; // for the presenter to differentiate between views
  12. end;
and then in 'DoEach' like this:
Code: Pascal  [Select][+][-]
  1. procedure TcsuModelMain.DoEach(const CurrentValue: string; aData: pointer);
  2. var ls: string; lid: integer;
  3. begin
  4.   if fSecId = -1 then exit;
  5.   ls:= LeftWord(CurrentValue);
  6.   lid:= IndexText(ls,sects);
  7.   if lid = fSecId then begin
  8.     IStringList(aData).Append(CurrentValue);  //bm
  9.     fInSection:= true;
  10.   end else begin
  11.     if fInSection then begin
  12.       case lid of
  13.         0..9: fInSection:= false; /// remember to adjust selector-values according to 'sects'
  14.       end;
  15.       if fInSection then IStringList(aData).Append(CurrentValue);
  16.     end;
  17.   end;
  18. end;
So I don't have to keep a fTmp pointing to 'Result'...
There isn't any 'Data' in a stringlist per se, only strings and objects...
One can also send a pchar along, f.e.: when one is searching... or PSomeRecord...
I think a 'DataLength' would be overkill and hint in the wrong direction...
Under other circumstances, I totally agree with you.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #32 on: November 26, 2024, 06:49:56 pm »
Hi
There was a small update today, namely:
Quote
26.11.2024 Updated istrlist.pas, version 8.26.11.2024
           (added: AssignToEx() & ScanFor() to IStrings)
The 'AssignToEx()' takes a 'TStrings' and a 'aClearFirst' parameter - does what the name says...
The 'ScanFor()' method allows you to iterate the stringlist and get the items that contains/matches the 'aStr' param, it sports a 'Userdata' param, in which you can send along anything you like and use in the callback method.
Regards Benny
« Last Edit: November 26, 2024, 06:56:02 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #33 on: November 28, 2024, 02:51:51 pm »
Hi
Well dang... Another update today too...
Quote
28.11.2024 Updated istrlist.pas, version 9.28.11.2024
           (added feature: 'AddOrSet' to IStrings - thanks Thaddy)
@Thaddy helped @Packs implement 'AddOrSet' as a helper for TStringlist, and he let me use his code in IStrings, so here it is...  :D
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #34 on: June 24, 2025, 08:35:57 pm »
Hi Y'all  ;D
I was doing a small demo-app with SQLite3 and figured "That would be cool to have built-in in IStrings...", so here goes, from the readme:
Quote
24.06.2025 Updated istrlist.pas, version 10.24.06.2025
           (added feature: 'AsBytes' property, nifty for sqldb-blob-fields, to IStrings)
           (added feature: 'AssignFrom' method to IStrings)
           (added factory: 'CreStrListFromStream')
           (added factory: 'CreStrListFromStrings')
Enjoy & happy coding  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #35 on: August 27, 2025, 11:56:20 am »
G'Day Mateys  :D
So I was made aware, that 'istrlist.pas' doesn't compile with FPC /fixes/ 3.2.4  :(
So here's a small update, to remedy that, from the Readme:
Quote
27.08.2025 Updated istrlist.pas, version 11.27.08.2025
           Corrected compiler defines to cater for FPC 3.2.4 /fixes/
           (added 3 overloaded methods: 'LoadFromStreamEx' to IStrings)
           (added 3 overloaded methods: 'SaveToStreamEx' to IStrings)
The new methods concerns those of you, who have started to use 'istreams.pas'...
Have fun & Happy coding  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Hansvb

  • Hero Member
  • *****
  • Posts: 864
Re: IStringList...
« Reply #36 on: August 27, 2025, 08:15:17 pm »
Hi Benny,

Because it is used in your MVP setup I replaced the istrlist.pas with the new one for a tool I'm working on. Don't notice anything. I mean that in a good sense. Everything just keeps going.   8)

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #37 on: August 27, 2025, 08:30:44 pm »
Hi Hans
Thanks mate, that I'm glad to hear \o/
I had to correct the compiler defines, 'cause @CharlyTango couldn't compile it with FPC /fixes/ ~ the upcoming 3.2.4  %)
...and another thank you for reminding me, to update the one in MVP-Setup  ;)
(pssst.: I totally forgot about that one  :-[  --Bad Benny--)  :D
I'll get right on it after my supper & football tonight  8-)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

cdbc

  • Hero Member
  • *****
  • Posts: 2522
    • http://www.cdbc.dk
Re: IStringList...
« Reply #38 on: November 25, 2025, 08:39:02 am »
Hi
Right, so after reading a post from @lar about 'TStringList.Reverse', I decided to implement that feature into 'IStrings', so that the resulting stringlist is a COM-Interface, which means -- you don't have to free it after use...  ;)
Code: Pascal  [Select][+][-]
  1. ...
  2. var org, rev: IStringlist;
  3. begin
  4.   org:= CreStrings;
  5.   org.Add('x'); org.Add('y'); org.Add('z');
  6.   { IStrings doesn't know about IStringlist, so we have to cast the result }
  7.   rev:= org.ReverseEx AS IStringlist;
  8.   writeln('Original:',lineending,org.Text,'Reversed:',lineending,rev.Text);
  9.   /// ADDED 15 minutes later ///
  10.   /// or you can just do:
  11.   org.ReverseSelf;
  12.   writeln('Original reversed:',lineending,org.Text);
  13. end;
So the new version is out now 12.25.11.2025 which adds new features 'ReverseEx' & 'ReverseSelf' to 'IStrings' along with moving the class into the interface section.
The 'ReverseSelf' method was inspired by @Zvoni :)
@BrunoK brought to my attention, that these 'Reverse' methods don't copy objects  :( So to remedy that I /reintroduced/ the 2 existing 'Reverse' methods and changed them slightly, to handle objects, strings and 'Self'.
End-effect: Now they cater for strings & objects properly.  ::)
So, Enjoy, have fun & happy coding  8-)
Regards Benny
« Last Edit: November 25, 2025, 04:03:05 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018