delphi - Error "Record, object or class type required" when using a wrapper type of an array -


i have got 2 arapper types easy handling /returning of one-dimensional arrays, , want write method convert 1 (a 2d-float-vector class 2d-int-point class). wrote simple one, throws errors 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);         := 0 vw.high         begin             x := round(vw[i].getx());             y := round(vw[i].gety());             vw[i] := tpoint(x,y);         end;         result := pw;     end;   end. 

these errors 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 ',' found [error] uutil.pas(27): declaration expected identifier 'result' found [error] uutil.pas(28): '.' expected ';' found 

dynamic arrays not objects, classes or records. not have methods defined on them.

instead of

vw.length 

you must write

length(vw) 

and likewise high.

next up, tpoint type. if want make new one, use helper function point().

then assign vw[i], surely mean assign pw[i].

finally, there's no need introduce local variable, , assign result local variable. can work directly on result. so, i'd write code this:

function topointarray(const vw: vector2farraywrapper): pointarraywrapper; var    i: integer; begin   setlength( result, length(vw));   := 0 high(vw)     result[i] := point(round(vw[i].getx), round(vw[i].gety)); end; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -