STRPTR function

Purpose

Return the 32-bit DWORD address of the memory block used to store the data held by a dynamic (variable length) string.

Syntax

xPtr = STRPTR(StringVar)

Remarks

StringVar is the name of a string variable.  STRPTR returns the 32-bit address in memory, where the contents of StringVar are stored.

Note that STRPTR differs from VARPTR.  When used with a string variable, VARPTR returns the address of the string's handle, while STRPTR returns the address of the actual string data.  Similarly, a STRING POINTER (or STRING PTR) is a pointer to a string handle - this important distinction should be recognized when working with the VARPTR and STRPTR operations.

STRPTR may not be used with fixed-length or ASCIIZ strings, because they do not use string handles.  Use VARPTR with fixed-length and ASCIIZ strings.

When a dynamic string content is changed, the address of the string data will also change, but the string handle will remain in the same location.  Therefore, it is important that your code refresh any pointers that target the string data memory locations directly.

See also

POKE$, PEEK$, VARPTR

Example

DIM x AS ASCIIZ PTR, A$

A$ = "PowerBASIC"

x = STRPTR(A$)   ' address of the string handle

Message$ = A$    ' returns A$

Message$ = @x    ' returns A$ as the target of x

A$ = "The power of BASIC!"

x = STRPTR(A$)   ' Update string pointer address

Message$ = @x    ' returns the target of x

Result

As the code above runs, Message$ is assigned the following strings:

PowerBASIC

PowerBASIC

The power of BASIC!