assign object content to other object without enum?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

assign object content to other object without enum?

17 Aug 2017, 04:19

For example I set array 'a' content same as 'b' and I know a := b or a := object(&b) do not overwrite old content but assign new address and old array still exist in memory. What I need is something like in 2nd example. So my question is here simpler method to do that? Erase array and refill it via loops take too much time.

Code: Select all

a := {1:"aaa"}
c := a
b := {1:"bbb"}
a := b
msgbox,% a.1 "`n" b.1 "`n" c.1 ; bbb / bbb / aaa

Code: Select all

a := {1:"aaa"}
c := a
b := {1:"bbb"}

a.Delete(a.MinIndex(),a.MaxIndex())
for k,v in b
	a[k] := v
msgbox,% a.1 "`n" b.1 "`n" c.1 ; bbb / bbb / bbb
Thenaks.
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: assign object content to other object without enum?

17 Aug 2017, 04:35

Would Clone() work?

Code: Select all

a := ["lul"]
b := a
c := a.Clone()
MsgBox % &a "`n" &b "`n" &c	; a and b has same address
a[1] := "lel"
MsgBox % a[1] "`n" b[1] "`n" c[1]	; a and b changed, c not
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

Re: assign object content to other object without enum?

17 Aug 2017, 05:37

not exactly.
Here is new example that should better visualise my problem.

Code: Select all

a := {Event:{1:"aaa"}} ; its my main object
b := a ; here some other code use my main object
f(a.Event) ; just unquote once of them to check
;f2(a.Event)
;f3(a.Event)
MsgBox % a.Event.1 "`n" b.Event.1 ; resoult should be bbb / bbb

f(ByRef array){ ; not working
	c := {1:"bbb"} ; here is my new content for a.Event.1
	array := c
}

f2(ByRef array){ ; WORKING
	c := {1:"bbb"} ; here is my new content for a.Event.1.
	;Instead of c := {...} I have other code and I can not directly work on 'array'
	
	;Now i replace oryginal content
	array.Delete(array.MinIndex(),array.MaxIndex()) ; Equivalent of array := c
	for k,v in c
		array[k] := v
}

f3(ByRef array){ ; not working
	c := {1:"bbb"} ; here is my new content for a.Event.1
	array := c.clone()
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Decar, doodles333, mikeyww and 224 guests