Am 26.05.2016 10:38 schrieb "LacaK" <la...@zoznam.sk>:
>
>
>>> is there way how to declare function, which will accept as parameter any
>>> array type ?
>>> (this parameter I need forward to System.Length() only )
>>
>> Generally one uses TArray<T> as parametertype. in such cases. One can
take
>> the length of a generic array.
>
> Hm,
> I do not understand.
>
> I need something like:
>
> function GetLength(const A): integer; inline;
> begin
>   Result := System.Length(A); // of course here I get "Type mismatch"
> end;
>
> Regular function, which I will call from generic object method as far as
inside generic object method I can not use System.Length()

Your problem is that you have a Length property in your class, so that's
why you need to use System.Length(). Try something like this:

=== code begin ===

type
  generic TMyHelper<T> = class
    class function GetLength(aArray: specialize TArray<T>): LongInt;
  end;

// in your object you do this:

type
  THelper = specialize TMyHelper<T>;

// and in your GetLength method you use THelper.GetLength(YourArray);

=== code end ===

Not tested, it might not compile as is (maybe you need to tweak around a
bit).
In general I can't recommend anything before 3.0.0 for serious use of
generics.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to