[fpc-pascal] How to declare function with untyped array parameter
LacaK
lacak at zoznam.sk
Thu May 26 08:32:42 CEST 2016
Hi,
is there way how to declare function, which will accept as parameter any
array type ?
(this parameter I need forward to System.Length() only )
Just like Length() function.
Now I fall into problem with generics , where I have in one unit generic
object, which has Length property (or Length function)
This function internally calls System.Length(A)
But when I specialize such generic in another unit, I give "Compilation
aborted" (FPC 2.6.4)
Culprit is prefix "System.".
When I omit prefix "System." then I give another error: Wrong number of
parameters specified for call to "Length"
(compiler is probably recognizing "Length" of object )
Example:
-----------------------------------------------------------------------------
1st unit:
generic GT<T> = object
private
var
FArray: array of T;
Fx, Fy: integer;
function GetLength: integer;
public
type
TElement = T;
PElement = ^T;
constructor Init; overload;
constructor Init(x,y: integer); overload;
property Length: integer read GetLength;
end;
function T2DArray.GetLength: integer;
begin
Result := System.Length(FArray); // <-- HERE prefix System is
causing "Compilation aborted" in FPC 2.6.4
end;
-----------------------------------------------------------------------------
2nd unit:
T2DIntArray = object(specialize GT<Integer>) end;
-----------------------------------------------------------------------------
Is there any workaround ?
Thanks
L.
More information about the fpc-pascal
mailing list