I've just started to migrate some of my ancient projects to SP20. There is one strange error (?) I have noticed so far. In a method call, depending on the circumstances I would like to return reference to an object, or an invalid reference:
Wow.... I missed this one in the manual - so there is a special syntax to invalidate a reference... Great :) Seems to work.
(it's just mentionned in the examples line)...
I've always assigned 0 to the variable, with := 0 - like setting a pointer to 0. In theory, that should work as well.
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This... is not very practical for me - as I have a bunch of different classes - it's just doesn't seems to be very practical to define a NULL for each of them...
Something like this I use in parameter definitions. For example:
I use this to prepare objects for code I don't control: Typycally visualizations - had many troubles with references set on the fly, right before opening a corresponding visualization...
And yes, the instance in GVL_Dummy reports itself as "Fake", so it does not influence the actual application at all. Actually this way I could invalidate a reference, just to set it to a "Dummy" instance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dear all,
I've just started to migrate some of my ancient projects to SP20. There is one strange error (?) I have noticed so far. In a method call, depending on the circumstances I would like to return reference to an object, or an invalid reference:
So far setting a reference variable to 0, did this. But now, the expression Add_EVT_OUT := 0; gives an error:
[ERROR] DB_WTP_370: Add_EVT_ACK MSG_TRIGGER_EXT: C0032: Cannot convert type 'BIT' to type 'REFERENCE TO FB_MSG'
Naturally... I can write:
But is this the correct way? Is there any constant I could use instead, like "NULL"?
Or this is totally wrong and to be avoided?
use this to set an invalid reference
Wow.... I missed this one in the manual - so there is a special syntax to invalidate a reference... Great :) Seems to work.
(it's just mentionned in the examples line)...
I've always assigned 0 to the variable, with := 0 - like setting a pointer to 0. In theory, that should work as well.
Thanks!
Last edit: Strucc.c 2024-03-25
You should use this method:
VAR
NULL:REFERENCE TO FB_MSG
END_VAR
Add_EVT_OUT REF= NULL;
This... is not very practical for me - as I have a bunch of different classes - it's just doesn't seems to be very practical to define a NULL for each of them...
Something like this I use in parameter definitions. For example:
I use this to prepare objects for code I don't control: Typycally visualizations - had many troubles with references set on the fly, right before opening a corresponding visualization...
And yes, the instance in GVL_Dummy reports itself as "Fake", so it does not influence the actual application at all. Actually this way I could invalidate a reference, just to set it to a "Dummy" instance.