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?
Copy only supports strings and
dynamic arrays, but not static or open array. So if you don't rely on
AddTriangles to have an open array as parameter you can use this:
type
TSingleArray = array of Single;
procedure TGraphic.AddTriangles(points: TSingleArray);
var
i: integer;
triangle: TTriangle;
chunk: TSingleArray;
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 main difference regarding open and dynamic array is that you can't call
AddTriangles like this if you use a dynamic array:
AddTriangle([4.5452, 2.4523, 1.5342]);
You have to use a dynamic array variable instead.
However with 3.2 and newer that works due to the dynamic array constructors.