[Solved]StrPut/StrGet &Address or Address?—a:=&a problem Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

[Solved]StrPut/StrGet &Address or Address?—a:=&a problem

11 Jun 2014, 21:36

In v2-changes, there is:
NumPut/NumGet: If a variable containing a pure number is passed to the VarOrAddress parameter, the variable's value is used rather than the address of the variable itself.
And I find it is suitable for StrPut/StrGet's arg Address.(While it's not metioned in v2-changes document.)
Means if the value of Address is a pure number, use Address directly, instead of &Address.
Am I understand correctly?

See posts below.
Last edited by RobertL on 26 Jun 2014, 06:02, edited 2 times in total.
我为人人,人人为己?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: StrPut/StrGet &Address or Address?

12 Jun 2014, 01:46

NumPut/NumGet uses the variable's own address in v2 if the variable doesn't contain a number.
NumPut/NumGet uses the variable's own address regardless of what it contains in v1.
StrPut/StrGet never uses the variable's own address when given a variable, in any version. If given a variable, it uses the variable's contents, which must be a numeric value - an address.
Means if the value of Address is a pure number, use Address directly, instead of &Address.
No, probably not. What is your intention? If that pure number is the address where the number/string can be found, then you would never use &Address. You would use either Address+0 (with v1 NumPut/NumGet) or just Address. You would only ever pass &Var to NumPut/NumGet/StrPut/StrGet if you wanted to store/retrieve a binary number or string in Var itself.
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: StrPut/StrGet &Address or Address?

12 Jun 2014, 05:43

lexikos wrote:If that pure number is the address where the number/string can be found, then you would never use &Address. You would use either Address+0 (with v1 NumPut/NumGet) or just Address.
Sorry, I omit my intention.
I understand Var and &Var. But the problem is about VarContainAddressor VarItself.
I find something very strange, when I migrate RaptorX/scintilla-wrapper SCI.ahk from V1 to V2.

Code: Select all

VarSetCapacity(lParam,..)
lParam:= &lParam
__sendEditor(this.hwnd, msg, wParam, lParam) ;get text, put it in lParam
StrGet(&lParam,..)  ;original use like this in V1.
StrGet(lParam,..)    ;I made this, so could work in V2.
I have done and could run the migrate, where there is not much syntax difference.
There is my fork with only migrate work (I'm an beginner).
And, there is all the comparison (only need to see diff stats SCI.ahk) It is simple and clear convertion I think.

Now, I'm confused why it use &lParam in StrGet, for lParam's content is aready address (only? in V2).
And there is an issue in Github (Also see, [Wrapper] Scintilla Wrapper v1.4.2.4 117# in autohotkey) with RaptorX/scintilla-wrapper, I think it is related with the problem.
我为人人,人人为己?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: StrPut/StrGet &Address or Address?

12 Jun 2014, 20:10

lParam:= &lParam takes the address of a variable, and then stores it back in the same variable. That isn't very sane, but should probably work. The problem might be that assigning the address in v2 converts the variable to a "pure number" variable, so the address which lParam contains doesn't actually represent the real content of the variable. This sort of dual usage can work, but is not supported (in the sense that you shouldn't do it; it mightn't work).

As soon as you assign a value to a variable, any address previously taken is potentially invalidated. In short, never do lParam:= &lParam.

Instead,

Code: Select all

VarSetCapacity(lParam,..)
__sendEditor(this.hwnd, msg, wParam, &lParam) ;get text, put it in lParam
StrGet(&lParam,..)
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: StrPut/StrGet &Address or Address?

12 Jun 2014, 20:43

Thank you very much. It's hard for me to find out the problem.
I will try,
in order to maintain compatibility—there are some code/sub process between VarSetCapacity and __sendEditor—I will use _:= &lParam, lParam:= _→see posts below.
Last edited by RobertL on 13 Jun 2014, 00:25, edited 4 times in total.
我为人人,人人为己?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: StrPut/StrGet &Address or Address?

12 Jun 2014, 21:10

That would have exactly the same problem. If you want the address to remain valid, don't reassign the original variable.
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

Re: StrPut/StrGet &Address or Address?  Topic is solved

12 Jun 2014, 21:39

Oh, :shock:
Now, I'm understand. Var with address allocation should not reassign.
Mayb, I have to use another var store the address, and change every lParam instance to var.
Use like this VarSetCapacity(lParamA,..),lParam:=&lParamA, which lParamA is the var keep allocation from VarSetCapacity.
我为人人,人人为己?

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww, Noitalommi_2 and 38 guests