Sorry for the delay, I had to spend some time trying to get my head
around what John had done, and still not totally sure.
Seemed almost like a bit of black magic in there…
John retrieved a set of country data into a Spring4D list, and then
using Spring4D’s IEnumerable iterator functionality was able to filter and
Sort the list in clever ways. How he did this was interesting, and not
in a way I would even think of, much less use, but maybe one day
soonish…
Back on the IEnumerable iterator, it seems to have many methods that I
could relate to. They had names like Select, Union, Or, And, First,
Order.
So I could likely do things with this list in a similar way to what I
might with an SQL query.
Apparently you could have multiple views? on the same IEnumerable??
Back to the IEnumerable processing.
For selecting items, I would perhaps write something like.
Result := True;
if Result and UseCriteria1 then Result := ApplyCriteria1(Params1);
if Result and UseCriteria2 then Result := ApplyCriteria2(Params2);
if Result and UseCriteria3 then Result := ApplyCriteria3(Params3);
A true result would result in the row/item being included.
John was instead creating a function at runtime using anonymous methods,
that only included/performed the required tests.
eg. Assuming only UseCriteria2 was True, the method that would be
created would only contain something like.
Result := True;
if Result then Result := ApplyCriteria2;
And the Params2 argument is actually supplied when the anonymous method was created.
This reminds me a little bit of building SQL on the fly and applying it.
It seemed to work well.
Thank you John,
I definitely have some more learning to do…