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

TEXT

Retrieve the class of an Edit Field


As you've discovered, TEHANDLE returns a handle to the field's "TextEdit Record." The TextEdit Record is something that's maintained by the MacOS (is not a uniquely-FB thing). On the other hand, the edit field's "class" _is_ something that's unique to FB, and FB stores it in a private data structure.

The simplest way to get the class of an edit field is to use the WINDOW(_efClass) function. There are two things you should note about WINDOW(_efClass):

* It only returns information about the currently-active edit field in the current output window. The "currently-active" field is essentially the one that's currently receiving keypresses. If none of the fields in the current output window is currently active, then the value returned by WINDOW(_efClass) is undefined.

* The number that it returns is actually the same number that you assigned as "justify + class" in the EDIT FIELD statement. This is somewhat confusing in the manual. You have to "tease out" the class number from the value returned by WINDOW(_efClass).

For example, if you create the edit field like this:
EDIT FIELD #5, "Hello", (10,50)-(100,66), _framedNoCR, _leftJust + myClass*4
Then the number you will get back from WINDOW(_efClass) is this:

_leftJust + myClass*4

To get back the original value of "myClass", use this:
EDIT FIELD #5, "Hello", (10,50)-(100,66), _framedNoCR, _leftJust + myClass*4
If you need to get the class number of a field which is not the currently active field in the current output window, you can use the WNDBLK function to help you do it. This is a little more complicated, but if you have a requirement to do it, let us know and we'll show you how.

Rick, my first reaction was that you are completely correct; but, on examination, the "teasing" doesn't prove out - unless I've missunderstood something. Since I just had a nap, I don't think so. Let's assume in the EF declaration above that myClass = 200 and we do exactly what you've noted. Doing that results in this: (I've just converted myClass to a string so it could be displayed in an EF.) class$ = STR$(WINDOW(_efClass)/4), from which class$ = "8" which is not 200;

The other thing I forgot to mention (and I don't think it's documented) is that the value of the "justify + class" expression can't be greater than 255, because FB stores it internally as an unsigned byte. This means that if you express the parameter as "_leftJust + myClass*4", then myClass should not exceed 63. If it does, you'll get unexpected results.

whereas if we do: EDIT FIELD #5, "Hello", (10,50)-(100,66), _framedNoCR, _leftJust + myClass 'Note: not *4 class$ = STR$((WINDOW(_efClass))-_leftJust) 'Of course _leftJust could be a variable too from which class$ has a value of "200" 'The only limitation being that myClass must be > 3

It's true that, as long as the full expression that you pass in the EDIT FIELD statement is less than 255 (as is the case with "200 + _leftJust"), then you'll get that full value back using the WINDOW(_efClass) statement.

But you have to be careful, because if the number that you add to the "justify" part is not a multiple of 4, then you'll mess up the text justification. For example, if you tried specifying this:

202 + _leftJust

Then you'd find that your edit field text was _right_ justified!

This happens because FB looks at the rightmost 2 bits in the expression (another way to say it is: "expression MOD 4") to determine the justification. If you add a multiple of 4 to the "justify" part, then those rightmost 2 bits are not altered, and everything's fine. But if you add something like 10 or 99 or 61 to the "justify" part, then you modify those 2 bits and mess up the justification.

Thus, if you want to stick with values that don't ruin your intended text justification, then you are limited to 64 unique values for the "class" part. If you like to express the parameter like this:

myClass + justification

then you should limit myClass to the values {0, 4, 8, 12, 16,...252}, and you can get "myClass" back using an expression like "4 * (WINDOW(_efClass) / 4)", or (if you know the justification value): "WINDOW(_efClass) - justification".

Or, if you like to express the parameter like this:

4*myClass + justification

then you should limit myClass to the values {0,1,2,3,4,...63}, and you can get "myClass" back using an expression like "WINDOW(_efClass) / 4".
Rick