[Pas2js] Testing generics
warleyalex
warleyalex at yahoo.com.br
Thu Oct 24 16:48:17 CEST 2019
//--------
type
generic TKeyValue<T> = class
private
FKey: string;
FValue: T;
procedure SetKey(const Value: string);
procedure SetValue(const Value: T);
//published // // target win64// Error: This kind of property cannot be
published
public
property Key : string read FKey write SetKey;
property Value : T read FValue write SetValue;
end;
{ TKeyValue<t> }
generic procedure TKeyValue<T>.SetKey(const Value: string);
begin
FKey := Value;
end;
generic procedure TKeyValue<T>.SetValue(const Value: T);
begin
FValue := Value;
end;
(...)
var
KV : specialize TKeyValue<Integer>;
begin
KV:= specialize TKeyValue<Integer>.Create;
KV.Key := 'FPC';
KV.Value := 2;
writeln('key=', KV.key, ' value=', KV.value);
end;
//---------------------------------------------------------
This code compiler, but when I run, it outputs this:
Uncaught TypeError: o.AfterConstruction is not a function ---> rtl.js:295
If I edit rtl.js and comment 295 line code: // o.AfterConstruction();
and re-compile the project, we have this expected console output: -->
key=FPC value=2
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list