Forum Navigation
You need to log in to create posts and topics.

A matter of pride (re. XREF question).

Posted by: wave <wave@...>

David:

I tested the code that I'd posted in my previous message about your XREF
problem and it worked fine. But it doesn't look like the post made it to
the list, so it's copied again below--please bear with this repost if
you've seen it already. This is one of the rare chances that I've had to
post something really useful to the group, so please give the code a try.
🙂

BTW, you asked earlier about using the XREF statement between functions. I
think you have to pass each function the handle to your memory block and
then restate the XREF statement inside every function that is using it.

____________old message_____________________
I'll take another stab at it, since memory management seems to be the one
thing I'm good at. 🙂
Also, my small brain couldn't understand Rick's answer.

Your code was this:
>
> DIM RECORD MyRec
> DIM MYmean!
> DIM 63 MYString$
> DIM END RECORD .MyRec
>
> _bazillion =1000000
> _realMax =1000
>
> XREF @ gList.MyRec(_bazillion)
>
> ---------------------------------------------------
> LOCAL FN enterData
> DIM myArray.Top&
>
> XREF@ myArray.MyRec(_realMax)
>
> myArray.Top& = gList.Top&
>
> FOR x = 1 TO 3
> myArray.MYmean!(x) = x + 0.001 'crash big time here!!!
> myArray.MYString$(x) = "The String"
> NEXT x
>
> 'FN printData
>
> err% = FN DISPOSHANDLE (myArray.Top&) 'trash handle when done
>
> END FN
>
> fn to set up handle:
> LOCAL FN setUpData
> gList.Top& = FN NEWHANDLE (3 * _MyRec)
> END FN
>
> fn to clean up after
> LOCAL FN trashData
> err% = FN DISPOSHANDLE (gList.Top&) 'trash handle when done
> END FN

The problem seems to go back to what XREF does. It doesn't create a memory
block, as Rick said--all it does is index a block that already exists.
Before you can index a block you must create it. So that's why the
gList.top& statement fixed the problem--it's the statement that actually
creates the block that you are going to index.

You should take the XREF statement out of the globals because there is
nothing to index until you create the block. In the globals section you
have not yet created the block, so there is nothing to index. Also, I
think XREF only works properly in local fns (if I remember a call to tech
support correctly in my early days of progamming).

In fact, I wouldn't even use a global variable for the handle to the block,
since a global implies that a value is going to exist for the life of the
program. Instead I would use a local variable and pass it through the
calling chain as necessary, but that's just my personal preference. So
here is my fix, for what it's worth.

>>
DIM RECORD MyRec
DIM MYmean!
DIM 63 MYString$
DIM END RECORD .MyRec

END GLOBALS

LOCAL FN enterData
DIM myArray&,err%,x

myArray& = FN NEWHANDLE (3 * _MyRec)
LONG IF myArray&
XREF@ myArray.MyRec(3)

FOR x = 0 TO 2
myArray.MYmean!(x) = x + 0.001 'crash big time here!!!
myArray.MYString$(x) = "The String"+STR$(x)
NEXT x

'___Put print statements here, of course____
FOR x=0 TO 2
PRINT USING "###.###";myArray.MYmean!(x)
PRINT myArray.MYString$(x)
NEXT x

DO
UNTIL LEN(INKEY$)

err% = FN DISPOSHANDLE (myArray&) 'trash handle when done
END IF
END FN

FN enterData
<<

PS. I took out the top& because it's an undefined value, which FB will
interpret as zero anyways.

__________________________
>I may have solved my XREF problem - but I'm worried that my solution does
>not accord with what I have read regarding XREF and arrays of records.

>All this seems to work - but how stable is it? I fear that it might be
>leaving a memory mess around since I have seen it fail, not on calling FN
>enterData, but on a subsequent menu operation.

____________________
Use e-mail with integrity.
M Goodes (wave@netcom.ca)