Oxygen Basic
Programming => Problems & Solutions => Topic started by: Brian Alvarez on December 10, 2018, 10:50:12 AM
-
Charles, i have tried everything and no solution has been found.
Even if i access the data directly at the address, the string remains the same after exiting the module.
it looks like the CHAR variable is being re-created rather than re-assigned, creating a completely different
address for the variable data.
Can you show me how to do it?
This is my non-working code:
FUNCTION BYREFPAR(byref char s) AS INT
MSGBOX str(@s) & chr(10, 13) & s, , "INSIDE BEFORE"
s = "* changed in module *"
MSGBOX str(@s) & chr(10, 13) & s, , "INSIDE AFTER"
END FUNCTION
FUNCTION PBMAIN2() AS INT
CHAR s[21]
s = "*ORIGINAL STR*" & CHR(0)
MSGBOX str(@s) & chr(10, 13) & s, , "OUTSIDE BEFORE"
BYREFPAR(s)
MSGBOX str(@s) & chr(10, 13) & s, , "OUTSIDE AFTER"
END FUNCTION
PBMAIN2() ' invoke entry point
-
By the way, couple more things... I also tried:
FUNCTION BYREFPAR(char *s) AS INT
Also...
FUNCTION BYREFPAR(byref char s) AS INT
MSGBOX str(@s) & chr(10, 13) & s, , "INSIDE BEFORE"
s = " hello " ' this is allowed but does not treat the variable as byref (creates a completely new data address)
s = ltrim(" hello ") ' this is not allowed, it doesnt compile.
MSGBOX str(@s) & chr(10, 13) & s, , "INSIDE AFTER"
END FUNCTION
I need to get this working, so i can start converting examples...
-
By the way, i can make it work by using a low level process, but i want to see if there is already an implemented way to do this.
-
Brian,
I think it has to be fairly low level for char*:
's = "* changed in module *"
copy strptr(s),"* changed in module *",len s
-
Got it!
Thats what i was thinking, so I implemented it that way. Just wanted to know if there was an implemented way already. :)
-
Actually, you can simplify it further. Copy understands strings and their pointers:
copy s,"* changed in module *",len s
-
Perfect, this way i can do it in one line. :)