Author Topic: Using Indexed String Pointers  (Read 2577 times)

0 Members and 1 Guest are viewing this topic.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 966
    • it-berater
Using Indexed String Pointers
« on: December 31, 2010, 09:47:24 AM »
I found this one, deeply digged in the PB Forum.

Watch the use of the stringptr @c[]!

Code: [Select]
#COMPILE EXE
#DIM ALL
#REGISTER NONE

FUNCTION PBMAIN

    DIM a(2) AS STRING
    DIM b(4) AS STRING
    DIM c AS STRING POINTER

    a(0) = "a0"
    a(1) = "a1"
    a(2) = "a2"

    b(0) = "b0"
    b(1) = "b1"
    b(2) = "b2"
    b(3) = "b3"
    b(4) = "b4"

    ' c = a
    c = VARPTR(a(0))
    MSGBOX @c[1]
    ' Returns "a1"

    ' c = b
    c = VARPTR(b(0))
    MSGBOX @c[3]
    ' Returns "b3"

    ' Change b
    b(3) = "TEST"
    MSGBOX @c[3]
    ' Returns "Test"

END FUNCTION
 

Another example:

Code: [Select]
#COMPILE EXE
#DIM ALL
#REGISTER NONE

FUNCTION PBMAIN

    DIM a(2) AS STRING
    DIM b(2) AS STRING
    DIM c(2) AS STRING
    LOCAL pc AS DWORD POINTER : pc = VARPTR(c())

    a(0) = "a0"
    a(1) = "a1"
    a(2) = "a2"

    b(0) = "b0"
    b(1) = "b1"
    b(2) = "b2"

    @pc = VARPTR(b(0))
    MSGBOX c(2)
    ' Returns "b2"

    b(2) = "TEST"
    MSGBOX c(2)
    ' Returns "TEST"

    @pc = VARPTR(a(0))
    MSGBOX c(2)
    ' Returns "a2"

END FUNCTION
« Last Edit: August 19, 2013, 07:55:42 PM by Theo Gottwald »