Recent

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

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: IStringList...
« Reply #30 on: August 20, 2024, 04:57:32 pm »
Just add datalength for data.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

cdbc

  • Hero Member
  • *****
  • Posts: 2616
    • 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: 2616
    • 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: 2616
    • 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: 2616
    • 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: 2616
    • 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: 887
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: 2616
    • 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: 2616
    • 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

d2010

  • Sr. Member
  • ****
  • Posts: 253
Re: IStringList...
« Reply #39 on: January 20, 2026, 07:37:11 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

Please, please, I  have many problems, ininside TstringList.AppendTofile
Inside TStringList.AppendToFile not exists . Can you you implement on IStrings?

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: IStringList...
« Reply #40 on: January 20, 2026, 08:17:55 am »
Would be better to implement that on TStringlist. AppendToFile is not implemented there.
What Benny (cdbc) does is mostly expose the existing methods through an interface.
TStringlist.AppendToFile is quite easy to implement, maybe on TStrings? Because that introduces SaveToFile. Or call that method AppendToFile (Actually all three methods.)
You could overload SaveToFile with an append boolean flag, for example, which would put the stream position at eof.
Implementing it only on IStringList makes no sense.
« Last Edit: January 20, 2026, 08:45:14 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

cdbc

  • Hero Member
  • *****
  • Posts: 2616
    • http://www.cdbc.dk
Re: IStringList...
« Reply #41 on: January 20, 2026, 10:57:53 am »
Hi
Thanks Thaddy =^

@d2010: Hmmmm.... Do you want me to go to the toilet for you too?!?
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   Classes
  10.   { you can add units after this }, istrlist;
  11.  
  12. procedure AppendToFile(const aFilename: string;aList: IStrings);
  13. var lsl: IStringList;
  14. begin
  15.   lsl:= CreStrListFromStrings(aList.AsTStrings);
  16.   aList.Clear;
  17.   aList.LoadFromFile(aFilename);
  18.   aList.AssignEx(lsl,false);
  19. end;
  20.  
  21. var
  22.   mainsl: IStringList;
  23.  
  24. begin
  25.   mainsl:= CreStrListFromFile('project1.lpr');
  26.   AppendToFile('project1.lpi',mainsl);
  27.   writeln(mainsl.Text);
  28. end.            
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

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: IStringList...
« Reply #42 on: January 20, 2026, 02:01:23 pm »
I wouid recommend to add appendtofile to TStrings and then adapt IStringlist to use it.
(Ping MvC, maybe)
Oh, I changed my profile, what do you think? Care to - temporary - loose a bit of your pension just for fun? I would. (actually sold my US bond funds today at a small profit, but I do think that is going to happen anyway: put the dog in its box, he has no economic power, the Netherlands can cut him , not the USA permantly, off of ASML just as easily as for China: no chips   ;D ;D ;D ;D ;D   Not to mention Danish intellectual property rights of several compilers  :D)

https://en.wikipedia.org/wiki/ASML_Holding
« Last Edit: January 20, 2026, 02:15:05 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

cdbc

  • Hero Member
  • *****
  • Posts: 2616
    • http://www.cdbc.dk
Re: IStringList...
« Reply #43 on: January 20, 2026, 02:32:53 pm »
Hi Thaddy
Michaël is a busy man and I'm sure he'll implement it, if he deems it necessary...
I've just showed "The Apprentice" just how unnecessary I find it!
I mean if he's struggling with 4 lines of code, then I don't know if I can help him  ;D
The functionality is all there, he just has to use it  8-)

The link looks interesting, I did not know that  ...and it would be a proper direction for some of my meager pension  :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

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: IStringList...
« Reply #44 on: January 20, 2026, 02:47:28 pm »
Well, a bark and a bite or WoofWoof, sit, paw:-X

But let's dream of a great green land, hardly spoiled nature, skies out, slaying with the dogs..

(But don't get distracted, keep on subject, Moi)
« Last Edit: January 20, 2026, 02:55:54 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018