Page 1 of 1

Problem with pointers

Posted: Tue Jan 31, 2023 8:51 pm
by Josepho
Hi im recently using pointers to have more efficient code in my app and im finding some weird behaviours that i cant explain, maybe im making any kind of beginner error as pointers is a thing i dont use very often

I have this code

Code: Select all

                SelectElement(imageFiles(),globalListMaps()\fileData)
                Debug "pointer value pre"
                Debug PeekS(imageFiles()\origURLp)
                Debug imageFiles()\origURLp
                
                RenameFile(globalProjectDirectory+globalListMaps()\fileURL,globalProjectDirectory+urltopaste+"/"+globalListMaps()\file)
                globalListMaps()\fileURL = urltopaste+"/"+globalListMaps()\file
                globalListMaps()\folderURL = urltopaste+"/"
                urlNew = urltopaste+"/"+globalListMaps()\file
                
                
                Debug "pointer value post"
                Debug PeekS(imageFiles()\origURLp)
                Debug imageFiles()\origURLp
And the log is returning the following

pointer value pre
assets/007-Swamp01.png
105553140510020
pointer value post

105553140510020
pointer value


Why is this happening? the pointer imageFiles()\origURLp = @globalListMaps()\fileURL

Any ideas? many thanks!

Re: Problem with pointers

Posted: Tue Jan 31, 2023 9:05 pm
by mk-soft
The rest of the code is missing. Without executable code, no idea.

Re: Problem with pointers

Posted: Tue Jan 31, 2023 9:11 pm
by STARGÅTE
Just a guess:
If imageFiles()\origURLp is a pointer to globalListMaps()\fileURL, this string pointer changes every time you change the string and imageFiles()\origURLp needs an update.

Re: Problem with pointers

Posted: Tue Jan 31, 2023 9:14 pm
by Josepho
Its what stargate is saying

Mmm but then how i keep the reference to the string if i need to change it?

Re: Problem with pointers

Posted: Tue Jan 31, 2023 9:24 pm
by STARGÅTE
You can't. You can save the pointer to the whole structure globalListMaps(), this element pointer keeps valid and you can trace down. The pointer has then the same structure as globalListMaps(), so that you can have access to the string.

Re: Problem with pointers

Posted: Tue Jan 31, 2023 9:27 pm
by Josepho
Ok many thanks for your help!

Re: Problem with pointers

Posted: Tue Jan 31, 2023 10:19 pm
by Josepho
Btw i found a solution thanks to Stargate feedback

I converted globallistmaps()\fileUrl into a .String class and the pointers are all .String too, and it appears to work as expected! :D