FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

FB II COMPILER

Know about handles of text



I think the "valid" format of a text handle depends on its context. In most cases I know of (for example, the handle to a block which contains an edit field's text), there is no length information contained with the text (there's no need for it, since the Memory Manager always keeps track of every handle's block length). A "ZTXT" block--which is something used only within FB and is not a generic "Mac thing"--starts with 2 bytes of length information, but that's the only such example I know of. A "Pascal string," which is the type held in FB string variables, begins with a single byte of length information. A Pascal string is not necessarily stored in a handle-type block.

If you have a _handle_ to a block, you can use that to get a _pointer_ to the block. The handle is just an address to a 4-byte area of memory. That 4-byte area in turn contains the address of the beginning of the block. So if the variable myHandle& contains the handle, then you can get the pointer as follows:

thePointer& = PEEK LONG(myHandle&)

or equivalently:

thePointer& = [myHandle&]

The only thing to remember is that the Memory Manager has control of the 4-byte area of memory that myHandle& points to, and may change its contents (this happens when the Memory Manager needs to relocate the block). If that happens, any copy that you made previously of the block's pointer (as in thePointer&) is no longer valid. That's why you usually want to "lock" the block before getting the pointer; locking the block keeps it from moving.

Rick