Hey Folks,
The dynamic string allocation question and my own "String Quickie" raise some interesting questions about string pointers. And I think there's a good deal of confusion about them.
I'm talking about type STRING, PB's dynamic strings (allocated by OLE, stored in ASCII, and managed by an internal handle-based system). I'll call them pbstrings for short.
The PB manuals tell us, correctly, that if we want a pointer to a pbstring's data, to use STRPTR, not VARPTR. It's exactly what you want when passing a data address to C or whatever.
But it's exactly what you DON'T want if you're using it for internal dreferencing to pbStrings. I have code to prove this following this message.
If you want to dereference a string pointer as ASCIIZ data, then you want STRPTR. But if you want to dereference it as the pbstring it is, you want VARPTR.
The syntax can seem counterintuitive:
Given:
local pS as string ptr, pZ as asciiz ptr, S as string
pS = strptr( S) 'THIS IS WRONG!
pS = varptr( S) 'THIS IS RIGHT
pZ = strptr( S) 'THIS IS RIGHT
You'd think you want to use STRPTR() to assign to a STRING POINTER, but not so. We don't want a pointer to the data, we want the internal handle so PB can handle it correctly.
Tested code follows in first reply.
The upshot of all this is that pb has a nice string subsystem. It allocates and disposes of OLE strings for us, but engine isn't exposed. It'd be great, for dynamic allocation needs, if we could tell PB, "I need another pstring. Give me the handle, and YOU remember to destroy it along with the rest when my program finishes."
Regards,
Brad
------------------
[This message has been edited by Bradley Olson (edited December 14, 2000).]
The dynamic string allocation question and my own "String Quickie" raise some interesting questions about string pointers. And I think there's a good deal of confusion about them.
I'm talking about type STRING, PB's dynamic strings (allocated by OLE, stored in ASCII, and managed by an internal handle-based system). I'll call them pbstrings for short.
The PB manuals tell us, correctly, that if we want a pointer to a pbstring's data, to use STRPTR, not VARPTR. It's exactly what you want when passing a data address to C or whatever.
But it's exactly what you DON'T want if you're using it for internal dreferencing to pbStrings. I have code to prove this following this message.
If you want to dereference a string pointer as ASCIIZ data, then you want STRPTR. But if you want to dereference it as the pbstring it is, you want VARPTR.
The syntax can seem counterintuitive:
Given:
local pS as string ptr, pZ as asciiz ptr, S as string
pS = strptr( S) 'THIS IS WRONG!
pS = varptr( S) 'THIS IS RIGHT
pZ = strptr( S) 'THIS IS RIGHT
You'd think you want to use STRPTR() to assign to a STRING POINTER, but not so. We don't want a pointer to the data, we want the internal handle so PB can handle it correctly.
Tested code follows in first reply.
The upshot of all this is that pb has a nice string subsystem. It allocates and disposes of OLE strings for us, but engine isn't exposed. It'd be great, for dynamic allocation needs, if we could tell PB, "I need another pstring. Give me the handle, and YOU remember to destroy it along with the rest when my program finishes."
Regards,
Brad
------------------
[This message has been edited by Bradley Olson (edited December 14, 2000).]
Comment