Sigh. we have Slice() as I demonstrated. It is also more efficient. It is built-in. No need to jump through hoops.
program test; {$mode delphi} var i: integer; thing: array [1..9] of single; slice: array of single; begin for i := 1 to 9 do thing[i] := i; SetLength(slice, 9); Move(thing[1], slice[0], 9*SizeOf(single)); for i := 1 to 9 do WriteLn(slice[i-1]) end.
It's just my working solution.Sigh. we have Slice() as I demonstrated. It is also more efficient. It is built-in. No need to jump through hoops.
program test; {$mode delphi} var i: integer; thing: array [1..9] of single; slice: array of single; begin for i := 1 to 9 do thing[i] := i; SetLength(slice, 9); Move(thing[1], slice[0], 9*SizeOf(single)); for i := 1 to 9 do WriteLn(slice[i-1]) end.
First check, then answer.
It's just my working solution.Fine with me but Slice() is a compiler intrinsic and therefor should be faster.
BTW. Move() must be fast and host, OS optimized just as C memmove().
Or you could simply write yourself a Copy Function that works the same way as the string Copy does.Jamie! slice()! >:D
Or you could simply write yourself a Copy Function that works the same way as the string Copy does.Jamie! slice()! >:D
Is that feature so obscure everybody fails to comprehend it.... <sigh> and that goes for all of you...
Or you could simply write yourself a Copy Function that works the same way as the string Copy does.Jamie! slice()! >:D
Is that feature so obscure everybody fails to comprehend it.... <sigh> and that goes for all of you...
Additionally, citation from your link: "but this array is not assignment compatible to any other array, and can therefor only be used in open array arguments to functions."Can you explain what you mean? Of course that is possible. That's part of my demo .The devil is in the detail.
So it is impossible to use slice() function in a construction like
a := slice(b, c);
Or you could simply write yourself a Copy Function that works the same way as the string Copy does.
function Copy(Const A:Array of Single;aStart:Integer;ACount:Integer=1):TSingleArray; var I:Integer; Begin SetLength(result, 0); If (Not AStart in [0..High(A)])or(Acount <= 0) then Exit; If ACount+AStart > Length(A) Then ACount := Length(A)-AStart; SetLength(Result, ACount); For I:= 0 To ACount-1 do Result[I] := A[AStart+I]; End;
That will start you in any location within the Array and then you specify the number of elements from that point on.
it returns an array created to the resolving size..
This will also test for limit control and not exceed the given array and simply return the remainder or nothing if it's outside the limits.
Or you could simply write yourself a Copy Function that works the same way as the string Copy does...Hmm, I can only envy the Delphi programmers, for some reason they always have the fastest processors, unlimited memory and the most understandable code.
You just killed me with laughter..... ;D ;DOr you could simply write yourself a Copy Function that works the same way as the string Copy does...Hmm, I can only envy the Delphi programmers, for some reason they always have the fastest processors, unlimited memory and the most understandable code.
Additionally, citation from your link: "but this array is not assignment compatible to any other array, and can therefor only be used in open array arguments to functions."Can you explain what you mean? Of course that is possible. That's part of my demo .The devil is in the detail.
So it is impossible to use slice() function in a construction like
a := slice(b, c);
Free Pascal Compiler version 3.3.1-r42722 [2019/08/17] for x86_64
Copyright (c) 1993-2019 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
test.pas(8,16) Error: SLICE cannot be used outside of parameter list
test.pas(9,16) Error: SLICE cannot be used outside of parameter list
test.pas(11) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
Why does this return a substring:
procedure TGraphic.AddTriangles(points: array of single); var i: integer; triangle: TTriangle; chunk: array of single; begin i := 0; while i < Length(points) - 1 do begin triangle := TTriangle.Create; chunk := Copy(points, i, 9); // HERE! triangle.SetPoints(chunk); inc(i, 9) end; end;
The error I get is:
Error: Incompatible types: got "ShortString" expected "{Dynamic} Array Of Single"
triangle.SetPoints expects array of single, why does Copy convert an array of single to shortstring?