[Lazarus] Generics diffence between Lazarus and Delphi Berlin

Sven Barth pascaldragon at googlemail.com
Tue Feb 28 14:18:14 CET 2017


Am 28.02.2017 09:37 schrieb "Andreas Frieß via Lazarus" <
lazarus at lists.lazarus-ide.org>:
>
> I have found some interesting working Generics construct. I want to
translate this code to Lazarus, but there are Generics often used.
> In Delphi Berlin the following ist working, the inner array of Integer is
normally 6 integer long, but once 7 integer and can filled in such way. Is
it possible to do something similar in Lazarus ? Or how can i rewrite this
to to the same in Lazarus/FPC

That has nothing to do with generics, but with array initializers, which
FPC currently doesn't support.
You can work around this by explicitly declaring the types and then using
.Create().

=== code begin ===

type
  TInnerArray = TArray<Integer>;
  TOuterArray = TArray<TInnerArray>;

var
  CODE_PATTERNS: TOuterArray;

begin
  CODE_PATTERN := TOuterArray.Create(
    TInnerArray.Create(2, 1, 2, 2, 2, 2),
    TInnerArray.Create(2, 2, 2, 1, 2, 2), TInnerArray.Create(2, 2, 2, 2, 2,
1), TInnerArray.Create(1, 2, 1, 2, 2, 3), ...
  );
end.

=== code end ===

While this looks quite verbose it should also work with Delphi. (In theory
TArray<Integer>.Create() and TArray<TArray<Integer>>.Create() directly
should work as well, but I think FPC's parser still barfs on that)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170228/f9faf896/attachment.html>


More information about the Lazarus mailing list