FluentQuery
FluentQuery copied to clipboard
AsTObjectList for compatible type?
I want to select from a list of Children of an FMX object all those that support a specific interface, but trying something like the following won't work since there's a plain AsTObjectList that returns a list of TObject, but not one that could return the type you tell it to. Internally the AsTList<OutT> would use "as OutT" and return TList<OutT>
Is there some other way to pull this out with a clean syntax?
type TStoryItemCollection = TList<IStoryItem>;
function TStoryItem.GetStoryItems: TStoryItemCollection; var IsStoryItem: TPredicate<TFmxObject>; begin IsStoryItem := function(obj: TFmxObject): Boolean begin Result := Supports(obj, IStoryItem); end;
result := ObjectQuery<TFmxObject>.Select.From(Children).Where(IsStoryItem).AsTList<IStoryItem>(false); end;