&Class.var ?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wdmodlin
Posts: 150
Joined: 16 Dec 2015, 02:42

&Class.var ?

10 Feb 2016, 21:06

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.
wdmodlin
Posts: 150
Joined: 16 Dec 2015, 02:42

Re: &Class.var ?

10 Feb 2016, 22:03

jethrow wrote:Try the GetAddress method
Thanks. That looks as though it may work... but just to check..
Should I use

Code: Select all

Class.GetAddress(var)
where i tried to use &class.var?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: &Class.var ?

10 Feb 2016, 22:04

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.
Class.GetAddress(var)
Only if var contains the name of the field.
wdmodlin
Posts: 150
Joined: 16 Dec 2015, 02:42

Re: &Class.var ?

11 Feb 2016, 00:21

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

Class.GetAddr("var"]
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.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: &Class.var ?

11 Feb 2016, 01:52

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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 218 guests