<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Ryan Joseph via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Fr., 29. Nov. 2019, 01:11:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Nov 28, 2019, at 6:38 PM, Sven Barth via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br>
> <br>
> TFPGObjectList has a constraint to class types, so you need to constrain your T as well using ": class". <br>
> <br>
> Please note however that you'll likely encounter another bug then once you move your function to a unit: <a href="https://bugs.freepascal.org/view.php?id=35943" rel="noreferrer noreferrer" target="_blank">https://bugs.freepascal.org/view.php?id=35943</a><br>
<br>
A better error would be nice but I guess I can't do this anyways until the other bug is fixed.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Why? It does say that a class type is expected. And the column of the error should point to the correct location. </div><div dir="auto">That's the same error you'd get when specializing outside of a generic with a non-class type. </div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
> The "specialize" is part of the generic identifier, so it must be "FGL.specialize TFPGObjectList<T>". <br>
> <br>
> That said however an internal error should not happen (especially the one I just added some days ago ^^'). Please report this one. <br>
> <br>
<br>
That doesn't look right to my eyes but ok. I filed a report (<a href="https://bugs.freepascal.org/view.php?id=36377" rel="noreferrer noreferrer" target="_blank">https://bugs.freepascal.org/view.php?id=36377</a>).<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The idea is that "specialize" belongs to the identifier just like "generic" does. This comes especially apparent for nested specializations:</div><div dir="auto"><br></div><div dir="auto">SomeUnit.specialize SomeType<... >.specialize SomeFunc<... ></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
It looks like my plan was foiled so I made a non-generic attempt. Can you explain why I get the EListError at runtime? I checked the itemSize property and it's the same for both lists.<br>
<br>
{$mode objfpc}<br>
<br>
program test;<br>
uses<br>
FGL;<br>
<br>
type<br>
TNode = class (TInterfacedObject)<br>
end;<br>
TNodeObjectList = specialize TFPGInterfacedObjectList<TNode>;<br>
<br>
function CopyList (source: TFPSList): TFPSList;<br>
begin<br>
result := TFPSList(source.ClassType.Create);<br>
result.Assign(source);<br>
end;<br>
<br>
var<br>
a, b: TNodeObjectList;<br>
begin<br>
a := TNodeObjectList.Create;<br>
// EListError: Incompatible item size in source list<br>
b := CopyList(a) as TNodeObjectList;<br>
end.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Can't tell right now from looking at it. Will need to test that later on. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>