Hi Thaddy
The 'aData' / 'UserData' is thought to be used like this:
function TcsuModelMain.GetStaticTexts(const aSection: string; out aTarget: integer): IStringList;
begin
if aSection = '' then exit(nil);
fSection:= '['+aSection+']'; fSecId:= IndexText(fSection,sects); // iterator-search
if fTextCache.Count = 0 then begin
fPresenter.Provider.NotifySubscribers(prStatus,nil,Str2Pch('(!) ERROR: Could NOT retrieve static texts!'));
exit(nil); /// maybe we should just comment this line and return an empty list, avoid AVs ///
end;
Result:= CreateStrList;
fTextCache.ForEach(@DoEach,Result);{ iterate over the source-list calling 'doeach' for each item }
aTarget:= fSecId; // for the presenter to differentiate between views
end;
and then in 'DoEach' like this:
procedure TcsuModelMain.DoEach(const CurrentValue: string; aData: pointer);
var ls: string; lid: integer;
begin
if fSecId = -1 then exit;
ls:= LeftWord(CurrentValue);
lid:= IndexText(ls,sects);
if lid = fSecId then begin
IStringList(aData).Append(CurrentValue); //bm
fInSection:= true;
end else begin
if fInSection then begin
case lid of
0..9: fInSection:= false; /// remember to adjust selector-values according to 'sects'
end;
if fInSection then IStringList(aData).Append(CurrentValue);
end;
end;
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