Problem with pointers

Just starting out? Need help? Post your questions and find answers here.
Josepho
User
User
Posts: 65
Joined: Thu Oct 22, 2020 7:01 am

Problem with pointers

Post 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!
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Problem with pointers

Post by mk-soft »

The rest of the code is missing. Without executable code, no idea.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Problem with pointers

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Josepho
User
User
Posts: 65
Joined: Thu Oct 22, 2020 7:01 am

Re: Problem with pointers

Post by Josepho »

Its what stargate is saying

Mmm but then how i keep the reference to the string if i need to change it?
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Problem with pointers

Post 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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Josepho
User
User
Posts: 65
Joined: Thu Oct 22, 2020 7:01 am

Re: Problem with pointers

Post by Josepho »

Ok many thanks for your help!
Josepho
User
User
Posts: 65
Joined: Thu Oct 22, 2020 7:01 am

Re: Problem with pointers

Post 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
Post Reply