<p>Am 14.12.2016 08:09 schrieb "Lars" <<a href="mailto:noreply@z505.com">noreply@z505.com</a>>:<br>
> A general purpose function that handles multiple types of arrays without<br>
> rewriting the code for each array type looks like this:<br>
><br>
>     procedure AddItemToArray(<br>
>       const item: {$I T.inc}; var arr: {$I TArr.inc}); overload;<br>
>     var len: integer;<br>
>     begin<br>
>       // below is the same for EVERY type! Reuse, Reuse!<br>
>       len:= length(arr);<br>
>       setlength(arr, len+1);<br>
>       arr[len]:= item;<br>
>     end;<br>
><br>
> Where $I T.inc defines the type being used.</p>
<p>Same code with 3.1.1's generics in non-Delphi mode:</p>
<p>=== code begin ===</p>
<p>generic procedure AddItemToArray<T>(<br>
       const item: T; var arr: specialize TArray<T>); overload;<br>
     var len: integer;<br>
     begin<br>
       // below is the same for EVERY type! Reuse, Reuse!<br>
       len:= length(arr);<br>
       setlength(arr, len+1);<br>
       arr[len]:= item;<br>
     end;</p>
<p>// used like this:<br>
specialize AddItemToArray<Longint>(42, myarr);</p>
<p>=== code end ===</p>
<p>> Maybe I reinvented generics. Advantage of this, is no OOP (object<br>
> orientation) required and it therefore works on any procedural code or OOP<br>
> code, not just OOP code alone.  One reason I dislike generics in modern<br>
> languages is that it almost always requires object orientation to be used<br>
> and you cannot program "generally" using procedural style coding. My<br>
> include file parametric polymorphism allows procedural code to be written<br>
> (such as dealing with simple arrays) generally.</p>
<p>FPC supports global generic routines (even in Delphi mode despite Delphi itself not supporting it).</p>
<p>Regards,<br>
Sven</p>