String Pointers
BlitzMax Forums/BlitzMax Programming/String Pointers
| ||
I'm trying to change a strings value via pointers but for some reason this isn't working..Local str:String = "Hello World!" test(Varptr str) Print str Function test(x:Byte Ptr) Local newStr:String = "CHANGED!" x = Varptr newStr End Function |
| ||
To do what you're trying to do you pass the 'object' in this case the String by reference using the Var keyword :Local str:String = "Hello World!" test(str) Print str Function test(strPtr:String Var) Local newStr:String = "CHANGED!" strPtr = newStr End Function |
| ||
Oh awesome, What's the difference between Var and Varptr? Does var pass the argument in as a reference? |
| ||
Var is by reference, yep. Varptr is usually used with a Ptr type variable, effectively giving you a new variable that is a pointer to a variable. In your case you want to change the value of the original variable itself, but in your example you were changing the value of the pointer to the variable. EDIT: edited for better a explanation. Last edited 2012 |