[futurebasic] Re: [FB] Printing questions

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 1999 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Tue, 3 Aug 99 01:25:46 -0500
>In trying TO figure how TO PRINT a spreadsheet type of arrays, I started
>TO examine the example code that IS available from so many sources. I
>found FN PrintFB
>
>First LINE, FieldHndl&=[WNDBLK+WindowNumber%*16+5] stopped me.
>
>The reference manual says that WNDBLK returns a pointer TO the
>compiler's window record. If that is the case, how does one get a handle
>by dereferencing a pointer? I thought deferencing a pointer got you the
>data address.
>
>THEN came:
>1       FieldPtr&       = [[[FieldHndl&]+8]]
>2       FieldNumber% = {[FieldHndl&]+4}           'FIELD NUMBER
>3       FieldType%     = PEEK([FieldHndl&]+6)     'FIELD TYPE
>4       FieldJust%     = PEEK([FieldHndl&]+7)     'FIELD JUST
>
> 1. I would have thought one deref rather than 3 would be enough TO GET
>a pointer unless the pointer IS stored in the WINDOW RECORD, but THEN
>how would the memory manager GET access TO itPRINT
> 2, 3, 4. Looks like another defer IS needed.

Stewart,

Yes, this does resemble a Gordian knot. Let me see if I can dissect it a 
bit.

WNDBLK is a pointer to the start of the window record block.

WNDBLK+WindowNumber%*16 is the start of the record for WindowNumber%.

WNDBLK+WindowNumber%*16+5 is, I'm confident, a typo, which should really 
be

WNDBLK+WindowNumber%*16+8, a pointer to the window's FB EDIT FIELD handle
                      which is stored at an offset of 8 from the beginning
                      of the record. Then

[WNDBLK+WindowNumber%*16+8] gets that handle from the address. In this 
                      case, the data _is_ a handle. 

Still with me? Let's try #1.

[FieldHndl&]    gives us a pointer to the FB EDIT FIELD record. 
                      Note that this is not yet a TEHANDLE&, but an FB
                      internal record (like the WNDBLOCK) that will
                      eventually get us to the TEHANDLE&.

[FieldHndl&]+8    points to the TEHANDLE field of the EDIT FIELD record. 
                      If we dereference it with
[[FieldHndl&]+8], we get an actual TEHANDLE&. (Again, the data stored 
                      here is a handle.) Now if we dereference the handle,
                      we do indeed get a pointer to the TERECORD:
FieldPtr& = [[[FieldHndl&]+8]]

Got it? Good. Lines 2, 3, and 4 simply access other data from the FB EDIT 
FIELD record. See the description on p. 341 of the Reference Manual.

The confusion is probably because we don't often come in contact with the 
FB EDIT FIELD record--I at first assumed it was a TERECORD, too.

Hope that helps.

 0"0
 =J= a  y
  "