[futurebasic] Re: [FB] [FB^3] Record Pointer Question

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2000 : Group Archive : Group : All Groups

From: Takaaki Mizuno <mizuno_takaaki@...>
Date: Tue, 14 Mar 2000 15:43:57 +0900
Hello.

BMichael@... wrote:
>I'm not sure if it's possible to use pointers and offsets with "real" 
>records. "testStr" is no longer a constant to the offset, thus 
>"p.testStr" is not going to give you a correct address. The point of the 
>new records is to use the real record name; could you not avoid pointers, 
>just DIM newRecord as testRecord, then use "newRecord.testStr(100)"?

The reason why I want to use pointers with true records is that
I am translating some source codes from C to FB^3.
Those C programs allocate memory for records dynamically.

According to "Appendix B: Variables" of the Reference Manual,
It may be possible to use pointers with true records. 
And I found that the following code worked fine.

-------------

BEGIN RECORD testRecord
 DIM testlong AS LONG
 DIM testStr AS STR255
END RECORD

BEGIN RECORD testRecord2
 DIM testptr AS POINTER TO testRecord
END RECORD

END GLOBALS

CLEAR LOCAL
LOCAL FN Test
 DIM p AS POINTER TO testRecord
 p = FN NewPtr _clear (SIZEOF(testRecord))
 p.testlong = 5
 p.testStr = "test"
 PRINT p.testStr; p.testlong
END FN

CLEAR LOCAL
LOCAL FN Test2
 DIM p AS POINTER TO testRecord
 DIM p2 AS POINTER TO testRecord2
 p2 = FN NewPtr _clear (SIZEOF(testRecord2))
 p2.testptr = FN NewPtr _clear (SIZEOF(testRecord))
 p2.testptr.testlong = 10
 p2.testptr.testStr = "test2"
 PRINT p2.testptr.testStr; p2.testptr.testlong
END FN

WINDOW #1
FN Test
FN Test2

STOP

---------------------

So, only true record that contains array cannot use with 
pointer (and handle). Is this a bug?



--------------
Takaaki Mizuno
mizuno_takaaki@..., takaaki@...
http://www1.cds.ne.jp/~takaaki/rinbrand/