Skip to content

AsTObjectList for compatible type? #7

Description

@birbilis

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 would use "as OutT" and return TList

Is there some other way to pull this out with a clean syntax?

type TStoryItemCollection = TList;

function TStoryItem.GetStoryItems: TStoryItemCollection;
var IsStoryItem: TPredicate;
begin
IsStoryItem := function(obj: TFmxObject): Boolean
begin
Result := Supports(obj, IStoryItem);
end;

result := ObjectQuery.Select.From(Children).Where(IsStoryItem).AsTList(false);
end;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions