Set REFERENCE to 0 (null) when no longer used

  • jtebokkel

    jtebokkel - 2020-05-25

    Is there a way to work around the error that happens when trying to set a reference to 0 after it isn't needed or is invalid? Trying to do this in codesys >= V3.5.15 results in an error. See example below. Now I could great a GVL with a bunch of unset references, but I'd end up with a large amount of null types.

    METHOD FB_init : BOOL
        bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
        bInCopyCode : BOOL;  // if TRUE, the instance afterwards gets moved into the copy code (online change)
        refLamp : REFERENCE TO FB_Lamp;
        byNewLevel : BYTE;
    IF (__ISVALIDREF(refLamp)) THEN
        THIS^.refLamp REF= refLamp;
        THIS^.refLamp REF= 0;
    THIS^.byNewLevel := byNewLevel;
  • jtebokkel

    jtebokkel - 2020-05-30

    ok, so I was playing around with some tests today and the code I was looking at I didn't actually try and build/run because I was missing libraries for it.

    Turns out you can build and run

    THIS^.refLamp REF= 0;

    it is just the precomplier that complains about it. Is this a bug then in the precompiler?


Log in to post a comment.