Error "Requires entry, object or class type" when using shell type for array

I have two types of arapper for simple processing / returning of one-dimensional arrays, and I want to write a method for converting one to another (2d-float-Vector class for 2d-int-point class). Wrote a simple one, but it just throws some errors that I don’t understand.

unit UUtil; interface uses UVector2f, Types, SysUtils; type Vector2fArrayWrapper = array of Vector2f; PointArrayWrapper = array of TPoint; implementation function toPointArray(vw : Vector2fArrayWrapper) : PointArrayWrapper; var pw : PointArrayWrapper; i,x,y : Integer; begin setLength(pw, vw.length); for i := 0 to vw.high do begin x := round(vw[i].getX()); y := round(vw[i].getY()); vw[i] := TPoint(x,y); end; result := pw; end; end. 

These are the errors I get:

 [Error] UUtil.pas(20): Record, object or class type required [Error] UUtil.pas(21): Record, object or class type required [Error] UUtil.pas(25): ')' expected but ',' found [Error] UUtil.pas(27): Declaration expected but identifier 'result' found [Error] UUtil.pas(28): '.' expected but ';' found 
+4
source share
1 answer

Dynamic arrays are not objects, classes, or records. They have no methods defined on them.

Instead

 vw.length 

you should write

 Length(vw) 

And similarly for high .

Next, TPoint is a type. If you want to create a new one, you use the helper function Point() .

Then you assign vw[i] , but of course you want to assign pw[i] .

Finally, there is no need to enter a local variable, and then assign Result this local variable. You can do all the work directly on Result . So, I would write the code as follows:

 function toPointArray(const vw: Vector2fArrayWrapper): PointArrayWrapper; var i: Integer; begin setLength( Result, Length(vw)); for i := 0 to high(vw) do Result[i] := Point(round(vw[i].getX), round(vw[i].getY)); end; 
+5
source

Source: https://habr.com/ru/post/1481562/


All Articles