delphi - Inaccessible field error -


sometimes when write class , test it, error in picture @ bottom, , when try debug editor shows me attributes want access "inaccessible values" (initializing them in constructor works surprisingly).

the last time got problem fixed copying code new unit , deleting old one, assumed had precompiled .dcu files. unfortunately tricky solution doen´t work class, did wrong or caused delphi 7 being outdated (i´m working on win8)?

unit uvector;  interface  uses      sysutils, types;  type      vector2f = class          private             x : extended;            y : extended;          public              function getx() : extended;             function gety() : extended;             constructor create(x,y : extended);             procedure add(v : vector2f);           end;   implementation  constructor vector2f.create(x,y : extended); // works! begin     self.x := x;     self.y := y; end;  procedure vector2f.add(v : vector2f); begin     //inc(x, v.getx());     // compiler error : left side cannot assigned     //inc(y, v.gety());     // compiler error : left side cannot assigned     self.x := self.x + v.getx(); //inaccessible value (at runtime) x , getx()     self.y := self.y + v.gety(); //inaccessible value (at runtime) y , gety() end;  function vector2f.getx() : extended; begin     result := x; end;  function vector2f.gety() : extended; begin     result := y; end;   end. 

error

first, on why inc not work, help on inc routine:

increments ordinal value 1 or n. ... x variable of ordinal type (including int64)...

extended not ordinal value type real value type.


secondly, on why getting access violation; av, when read address approaches zero, chances accessing unassigned object variable, results in inaccessible value debugger hint.

this test code works:

procedure tform1.button1click(sender: tobject); var   v1: vector2f;   v2: vector2f; begin   v1 := vector2f.create(123.45, 234.56);   v2 := vector2f.create(123.45, 234.56);   try     v1.add(v2);     caption := floattostr(v1.getx);  // outputs 246.9       v2.free;     v1.free;   end; end; 

thus, 1 of following causes @ hand:

  • you haven't created object work on,
  • you haven't created object passing.

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 -