Recent

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

Thaddy

  • Hero Member
  • *****
  • Posts: 16138
  • Censorship about opinions does not belong here.
Re: IStringList...
« Reply #30 on: August 20, 2024, 04:57:32 pm »
Just add datalength for data.
If I smell bad code it usually is bad code and that includes my own code.

cdbc

  • Hero Member
  • *****
  • Posts: 1644
    • 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 -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

cdbc

  • Hero Member
  • *****
  • Posts: 1644
    • 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 -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

cdbc

  • Hero Member
  • *****
  • Posts: 1644
    • 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 -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

 

TinyPortal © 2005-2018