Hi!
I want to have a generic function inside a non-generic class. Something like that
program project1;
{$mode objfpc}
type
generic grec<T> = record
value: T;
end;
tmytype = class
public
generic function func1<T>( const v: variant ): specialize grec<T>;
end;
var
tmp: tmytype;
vr: variant;
res: string;
gr: specialize grec<string>;
generic function tmytype.func1<T>( const v: variant ): specialize grec<T>;
begin
result.value := t(v);
end;
generic function func11<T>( const v: variant ): specialize grec<T>;
begin
result.value := t(v);
end;
begin
vr := 123;
tmp := tmytype.Create;
//with tmp do
gr := specialize tmp.func1<string>( vr );
writeln(gr.value);
tmp.Free;
writeln(specialize func11<string>( vr ).value);
readln;
end .
But it does not compile giving error
project1.lpr(35,21) Fatal: Syntax error, "<" expected but "." found
on line
gr := specialize tmp.func1<string>( vr );
The "with" clause does not work either with "project1.lpr(35,31) Error: Illegal expression"
with tmp do
gr := specialize func1<string>( vr );
The func11 works fine after all.
Is it not supported or am I missing something?
Lazarus 2.0.10, fpc 3.2.0, x64
Thanks