[Pas2js] Testing generics
Mattias Gaertner
nc-gaertnma at netcologne.de
Sun Oct 27 22:39:20 CET 2019
On 26.10.19 14:03, warleyalex via Pas2js wrote:
> Another thing is:
> I would like to create a procedure, e.g. a list of people, without the use
> of generics; and another with the use of generics.
>
> ---// CODE -----------------
> uses
> JS, Classes, SysUtils, Web, Types, Math, TypInfo,
> generics.collections, generics.defaults, generics.strings;
>
> {$mode objfpc}
>
> type
> TPerson = class
> private
> FNome: String;
> procedure SetNome(const Value: String);
> public
> property Nome: String read FNome write SetNome;
> end;
>
> { TPerson }
> procedure TPerson.SetNome(const Value: String);
> begin
> FNome := Value;
> end;
>
> procedure PersonWithoutGenerics;
> var
> LListaPessoa: TList; //--> Error: Generics without specialization cannot
> be used as a type for a variable
> begin
>
> end;
>
> procedure PersonWithGenerics;
> var
> LListaPessoas: specialize TList<TPerson>;
> begin
>
> //-----------------
> The problem is that the compiler shows:
>
> Error: Generics without specialization cannot be used as a type for a
> variable
Fixed.
Mattias
More information about the Pas2js
mailing list