FluentQuery icon indicating copy to clipboard operation
FluentQuery copied to clipboard

AsTObjectList for compatible type?

Open birbilis opened this issue 3 years ago • 0 comments

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;

birbilis avatar Oct 16 '21 09:10 birbilis