Date:  11/10/2004 08:48:52 AM Msg ID:  002346
From:  Jim Doe Thread:  002346
Subject:  Array / Function question
Hi all
 
The Apology:
I know that this is more of a FoxPro question, but since I do all of my FoxPro coding by way of FoxWeb, and since there isn't one dominant discussion board for FP, I thought I'd pose this issue here.  Apologies to those who might be offended by this.  Besides, this group is, by far, the sharpest FoxPro group out there!  (Where's the 'Shameless Flattery' emoticon?)
 
The Issue:
When passing an array to a function (by reference), the function whittles down the array via re-dimensioning.  Based upon certain criteria, the array should be emptied and since "Dimension Arr(0)" won't work, I used a "Release Arr" instead.  A quick test as to the existence of "Arr" proved that the array had in fact been released.  However, when the function ended, I discovered that the array that had been passed to the function and subsequently RELEASEd was still alive and well.  I'm almost certain that this isn't by design.  My biggest fear is that the memory of the array is in fact released back into the free memory pool and subsequent program execution will stomp all over it.  I can code around it, but I just wanted to know if this is a bug, misunderstanding or stupidity on my part.  I'm using Visual FoxPro 7 with FoxWeb 2.6.
 
Added Follow-Up:
Within the function, the array can be altered with the "Dimension" command and those changes are seen in the calling program
 
The Example:

<html>
<head>
</head>
<body>
<H2>Hi There</h2>

<%
Dimension Items(20)
response.write(alen(items))
response.write("<br>")
response.write(Whittle(@items))
response.write("<br>")
response.write(alen(items))
response.flush()


Function Whittle(Arr)
  * - Just for fun, kill the array
  release Arr
  * - The next line will cause "Variable 'ARR' is not found", as it is supposed to - Uncomment to see
  * response.write(alen(arr))
  return 0
  endfunc
%>
</body>
</html>

 
Produces...

Hi There

20
0
20
 
Since the array is passed by reference, I would have thought that the second "alen" call would either cause an error or yeild a 0.  Any thoughts? 
 

-Jim


"The true measure of a career is to be able to be content, even proud that you succeeded through your own endeavors without leaving a trail of casualties in your wake."  - Allen Greenspan