If course I tried that, because TDemoObjectList = class(TObjectList<TDemoObjectListItem>) inherits from TEnumerable<T>.
But I get the following:
OVMDemo.UI.FormMain.pas(76,53) Error: Incompatible type for arg no. 1: Got "TDemoObjectList", expected "TEnumerable<OVMDemo.DemoData.TDemoObjectList>"
As an alternative, I'm looking into simply passing the class helper a TObject and reacting properly in there,
see line 1197ff:
procedure TObjectListViewClassHelper.DisplayItems(AList: TObject);
procedure DisplayCollection(ACollection: TCollection);
var
ci: TCollectionItem;
li: TListItem;
begin
for ci in ACollection do begin
li := Self.Items.Add;
Self.UpdateListItemForObject(li, ci);
end;
end;
begin
Self.Items.BeginUpdate;
try
Self.Items.Clear;
Self.Columns.Clear;
if AList is TCollection then begin
DisplayCollection(AList as TCollection);
end else begin
// it would be great if generic collections could be detected here
OutputDebugString(PChar(string(AList.ClassParent.ClassName)));
// test 1: detect class
//if AList.ClassParent.ClassName is TObjectList then begin
// fails because is cannot be used here
//end;
// test 2: rtti? won't work because public, not published
//property Count: SizeInt read FLength write SetCount;
//property Items[Index: SizeInt]: T read GetItem write SetItem; default;
end;
finally
Self.Items.EndUpdate;
end;
end;
But it seems that
is does not work on generics without specialization:
OVM.ListView.pas(1281,44) Error: Generics without specialization cannot be used as a type for a variable
Problem is that I
want to work on any, without specialization
Am I missing the right syntax, or is it not possible to "detect" the abstract generics type of a type based on generics?
I could use ClassParent.ClassName to detect that the parent class is TObjectList<something>, but still would not know how to access properties.
At this stage, it's mostly interest, since it's now working and I published this package mostly because I want to publish a larger one where this is used in an example. And I like to improve things
(PS: FreePascal 3.3.1-1245 from 2023/02/06... will update my trunk environmen asap)