Set constant in object
prolow
Posts: 3
Is there a way to set a constant in a object from a method?
For example:
TopLevelObj.spin
For example:
someObjWithConst.spin CON bla = 0
TopLevelObj.spin
OBJ subObj : someObjWithConst Pub subObj.bla := 6
Comments
You can use a constant like this:
You cannot use dot-notation to change variables inside constants, either; you must provide an interface method to make that change.
TopObject.spin
SubObject.spin
Often a child object will have a buffer which needs to be sized to match a constant. It would be nice if these child objects could remain unchanged when these buffers are resized. As it is, I need a separate child object for each size of buffer a program needs.
Serial objects are a good example of objects which would benefit from this sort of system.
-Phil
I sometimes go this route but it makes it harder to keep things modular. It would be really nice if there were a "#" type of notation which worked the opposite direction.
But what if two objects do this to the same child, but with different values? The code and DAT portions of objects are shared amongst all instances. So there would be a conflict. I think Chip was right in not allowing "remote" CONstant definitions.
-Phil
I might start doing this with some of my projects but I was kind of thinking of objects to place in the OBEX where the person using the object wouldn't have to know much about how to set it up to use the object. Though it could be argued (probably correctly) setting constants used by the child in the parent is hardly modular.
In these cases the compiler would need to keep separate copies of the object.
I won't disagree. I'll have to find something else to whine about. Give me a minute and I'll come up with something.