Thanks for that - I will give it a try :)
On 27/07/14 21:21, leledumbo wrote:
It is only a personal preference, not a serious problem.
I would find code in the form of
ArrayLen := IncLength(ArrayName, 1);
to be much more readable then
SetLength(ArrayName, Length(ArrayName)+1);
ArrayLen:= High(ArrayName);
I was just hoping somebody may know how its done.
Without support for generic function, currently you have to use generic
class method:
type
generic TDynArrayUtil<T> = class
public
class function SetLength(var a: T; const n: Integer): Integer;
end;
class function TDynArrayUtil.SetLength(var a: T; const n: Integer): Integer;
begin
System.SetLength(a,Length(a) + n);
Result := High(a);
end;
and use it like:
var
a: TIntegerDynArray;
...
maxn := specialize TDynArrayUtil<TIntegerDynArray>.SetLength(a,1);
note that you have to instantiate with the correct type.
--
View this message in context:
http://free-pascal-general.1045716.n5.nabble.com/SetLength-procedure-tp5719807p5719810.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal