Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2017-02

Generics diffence between Lazarus and Delphi Berlin

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andreas Frieß

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

Andreas

var
   CODE_PATTERNS: TArray<TArray<Integer>>;
........
   CODE_PATTERNS :=  [[2, 1, 2, 2, 2, 2], // 0
   [2, 2, 2, 1, 2, 2], [2, 2, 2, 2, 2, 1], [1, 2, 1, 2, 2, 3],
     [1, 2, 1, 3, 2, 2], [1, 3, 1, 2, 2, 2], // 5
   [1, 2, 2, 2, 1, 3], [1, 2, 2, 3, 1, 2], [1, 3, 2, 2, 1, 2],
     [2, 2, 1, 2, 1, 3], [2, 2, 1, 3, 1, 2], // 10
   [2, 3, 1, 2, 1, 2], [1, 1, 2, 2, 3, 2], [1, 2, 2, 1, 3, 2],
     [1, 2, 2, 2, 3, 1], [1, 1, 3, 2, 2, 2], // 15
   [1, 2, 3, 1, 2, 2], [1, 2, 3, 2, 2, 1], [2, 2, 3, 2, 1, 1],
     [2, 2, 1, 1, 3, 2], [2, 2, 1, 2, 3, 1], // 20
   [2, 1, 3, 2, 1, 2], [2, 2, 3, 1, 1, 2], [3, 1, 2, 1, 3, 1],
     [3, 1, 1, 2, 2, 2], [3, 2, 1, 1, 2, 2], // 25
   [3, 2, 1, 2, 2, 1], [3, 1, 2, 2, 1, 2], [3, 2, 2, 1, 1, 2],
     [3, 2, 2, 2, 1, 1], [2, 1, 2, 1, 2, 3], // 30
   [2, 1, 2, 3, 2, 1], [2, 3, 2, 1, 2, 1], [1, 1, 1, 3, 2, 3],
     [1, 3, 1, 1, 2, 3], [1, 3, 1, 3, 2, 1], // 35
   [1, 1, 2, 3, 1, 3], [1, 3, 2, 1, 1, 3], [1, 3, 2, 3, 1, 1],
     [2, 1, 1, 3, 1, 3], [2, 3, 1, 1, 1, 3], // 40
   [2, 3, 1, 3, 1, 1], [1, 1, 2, 1, 3, 3], [1, 1, 2, 3, 3, 1],
     [1, 3, 2, 1, 3, 1], [1, 1, 3, 1, 2, 3], // 45
   [1, 1, 3, 3, 2, 1], [1, 3, 3, 1, 2, 1], [3, 1, 3, 1, 2, 1],
     [2, 1, 1, 3, 3, 1], [2, 3, 1, 1, 3, 1], // 50
   [2, 1, 3, 1, 1, 3], [2, 1, 3, 3, 1, 1], [2, 1, 3, 1, 3, 1],
     [3, 1, 1, 1, 2, 3], [3, 1, 1, 3, 2, 1], // 55
   [3, 3, 1, 1, 2, 1], [3, 1, 2, 1, 1, 3], [3, 1, 2, 3, 1, 1],
     [3, 3, 2, 1, 1, 1], [3, 1, 4, 1, 1, 1], // 60
   [2, 2, 1, 4, 1, 1], [4, 3, 1, 1, 1, 1], [1, 1, 1, 2, 2, 4],
     [1, 1, 1, 4, 2, 2], [1, 2, 1, 1, 2, 4], // 65
   [1, 2, 1, 4, 2, 1], [1, 4, 1, 1, 2, 2], [1, 4, 1, 2, 2, 1],
     [1, 1, 2, 2, 1, 4], [1, 1, 2, 4, 1, 2], // 70
   [1, 2, 2, 1, 1, 4], [1, 2, 2, 4, 1, 1], [1, 4, 2, 1, 1, 2],
     [1, 4, 2, 2, 1, 1], [2, 4, 1, 2, 1, 1], // 75
   [2, 2, 1, 1, 1, 4], [4, 1, 3, 1, 1, 1], [2, 4, 1, 1, 1, 2],
     [1, 3, 4, 1, 1, 1], [1, 1, 1, 2, 4, 2], // 80
   [1, 2, 1, 1, 4, 2], [1, 2, 1, 2, 4, 1], [1, 1, 4, 2, 1, 2],
     [1, 2, 4, 1, 1, 2], [1, 2, 4, 2, 1, 1], // 85
   [4, 1, 1, 2, 1, 2], [4, 2, 1, 1, 1, 2], [4, 2, 1, 2, 1, 1],
     [2, 1, 2, 1, 4, 1], [2, 1, 4, 1, 2, 1], // 90
   [4, 1, 2, 1, 2, 1], [1, 1, 1, 1, 4, 3], [1, 1, 1, 3, 4, 1],
     [1, 3, 1, 1, 4, 1], [1, 1, 4, 1, 1, 3], // 95
   [1, 1, 4, 3, 1, 1], [4, 1, 1, 1, 1, 3], [4, 1, 1, 3, 1, 1],
     [1, 1, 3, 1, 4, 1], [1, 1, 4, 1, 3, 1], // 100
   [3, 1, 1, 1, 4, 1], [4, 1, 1, 1, 3, 1], [2, 1, 1, 4, 1, 2],
     [2, 1, 1, 2, 1, 4], [2, 1, 1, 2, 3, 2], // 105
   [2, 3, 3, 1, 1, 1, 2]];

Reply by email

Sven Barth
to Andreas Frieß

Am 28.02.2017 09:37 schrieb "Andreas Frieß via Lazarus" <

: 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>

Reply by email