Page 1 of 1

&Class.var ?

Posted: 10 Feb 2016, 21:06
by wdmodlin
I'm still struggling through some basics here.. Please tell me where I have something wrong.

For most purposes, it seems that I can treat "Class.var" and "var" as interchangeable, once "Class.var" has been assigned a value.

To avoid possible conflicts between instance variables and base-class static variables of the same name, I have adopted the habit of always using "base.var" and "this.var" instead of just "var" even where "var" would work. I use unqualified names for function-local variables that are not intended to be shared among methods.

I tried calling a DLL with an argument &base.var, expecting it to change the "var" declared as static in base.

It did not change base.var.

So I used &localvar, and after the call did base.var := localvar. That fixed the problem, but it feels a bit awkward.

Is there a syntax for properly taking the address of base.var?

Or did I mis-interpret my results?

Any clarifications would be appreciated.

Re: &Class.var ?

Posted: 10 Feb 2016, 21:46
by jethrow
Try the GetAddress method

Re: &Class.var ?

Posted: 10 Feb 2016, 22:03
by wdmodlin
jethrow wrote:Try the GetAddress method
Thanks. That looks as though it may work... but just to check..
Should I use

Code: Select all

where i tried to use &class.var?

Re: &Class.var ?

Posted: 10 Feb 2016, 22:04
by lexikos
For most purposes, it seems that I can treat "Class.var" and "var" as interchangeable
Class.var is an expression. Anywhere that you can use an expression to compute a value, you can use Class.var. Class.var returns a value, not a variable reference. If it returned "value", for instance, &Class.var would be equivalent to &"value".
I have adopted the habit of always using "base.var"
Don't do literally that; use the class name. You can use base.var in a method to refer to a property in the base class (not the current class or the object's base), but base.var := x will not work unless var is implemented by a property setter or meta-function. It works for reading static variables too, but if you make using it a habit, you're more likely to confuse yourself when you need to assign a value.
Only if var contains the name of the field.

Re: &Class.var ?

Posted: 11 Feb 2016, 00:21
by wdmodlin
Again, thank you Lexikos
Don't do literally that;...
In fact I have been using Class.var, not literally "base.var".

I am still fuzzy about base... I suppose understanding will come with time.

You say "Only if var contains the name of the field". Hmm. Ok. Does that mean that I should instead code:

Code: Select all

That makes sense, assuming it is true.

Another question. How are you getting those neat in-line boxes that you use where I would say "base.var"? I was not familiar with any of this stuff just a few weeks ago, I'm happy just to have figured out how to put in a code box, but there is a lot more to learn.

Re: &Class.var ?

Posted: 11 Feb 2016, 01:52
by lexikos
Just add quotes if it's meant literally: xx.var -> xx.GetAddress("var") or xx[yy] -> xx.GetAddress(yy) (yy is a variable containing a key).

For the inline code, I just type [ c ] the code [ / c ] without spaces. There's also a "c" button in the full post editor.

If you want to know how to duplicate formatting that you see in someone's post, you can view the "source code" of the post by quoting it.