Passing a string to a procedure by reference

Share your advanced PureBasic knowledge/code with the community.
Axeman
User
User
Posts: 99
Joined: Mon Nov 03, 2003 5:34 am

Passing a string to a procedure by reference

Post by Axeman »

Code: Select all


; This procedure receives a string passed by reference and outputs its value via the 'Debug' command.
; Note that the string is stored in the 's' field of the default 'STRING' structure.
Procedure Test1( *str_pointer.STRING )
Debug *str_pointer\s
EndProcedure


; This procedure receives a string passed by reference and changes its value.
; Note that the string is stored in the 's' field of the default 'STRING' structure.
Procedure Test2( *str_pointer.STRING )
*str_pointer\s = "def"
EndProcedure


; This procedure passes strings by reference to the previous procedures to test the result.
; Note that the string is stored in the 's' field of the default 'STRING' structure. All reading and writing should be done with that field.
Procedure Test3()
Protected mystring.STRING
mystring\s = "abc"
Test1( @mystring )
Test2( @mystring )
Debug mystring\s
EndProcedure


Test3()