How can I slice a dynamic array to multiple sub arrays? Slice()
function in Delphi does not support dynamic arrays. So how can it be done? A generic solution would be welcome.
program Project10;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
A: Array of Integer;
begin
SetLength(A, 4);
Slice(A, 2); // [dcc32 Error] Project10.dpr(15): E2193 Slice standard function only allowed as open array argument
end.
Use Copy(A, 0, 2)
instead of Slice(A, 2)
.
The point is that either you need an "open array parameter" (in which case you need Slice
) or you need a regular array, in which case Copy
will provide a good solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With