Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Deane Robieson
  Where is Deane Robieson?
 Auckland
 New Zealand
 Deane Robieson
 To: Bernard Bout
  Where is Bernard Bout?
 Brisbane
 Australia
 Bernard Bout
Subject: RE: Objects in an array
Thread ID: 93481 Message ID: 93632 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 Category: Forms
Date: Tuesday, April 18, 2006 11:19:15 PM         
   



> > Hi again everyone.
> >
> > I am trying to build a calendar display that will give me a few options I can't find elsewhere (specifically, the ability to select a number of days at a time).
> >
> > While experimenting with how to achieve this, I have come across a wee problem.
> >
> > I have a form with a single checkbox on it and two command buttons.
> >
> > In the load method of the form, I declare an array...
> > Declare aCalendar(1,1)
> >
> > In the init method of the checkbox, I have the following code...
> > aCalendar(1,1) = This
> >
> > I have the following code in the click method of command1...
> > if aCalendar(1,1).enabled = .t.
> > aCalendar(1,1).enabled = .f.
> > else
> > aCalendar(1,1).enabled = .t.
> > endif
> >
> > All this works fine - clicking the command button changes the enabled proberty of the checkbox as I suspected it would and the display of the checkbox changes with each click to reflect it's enabled / disabled status.
> >
> > My problem is that, in the cliek method of command2, I have the code...
> > release all
> > thisform.release
> >
> > I expected the form to be released when I click this button, but it doesn't. If I run the form without the code aCalendar(1,1) = this, then the form will release as usual. Putting the above code back recreates the problem.
> >
> > What have I missed please ?
> >
> > Thanks.
> >
> > Deane

>
> Hi Deane
>
> You cannot expect to have this code in the form load "Declare aCalendar(1,1)" and expect it to be in scope in the rest of the form. I have just tried what you suggested and the array goes out of scope. So you must be declaring it somewhere else before the form starts so that it is in scope.
>
>
> Therefore this line will NOT work:
>
> >In the init method of the checkbox, I have the following code...
> > aCalendar(1,1) = This
>
> as aCalendar(1,1) is out of scope and you will get a "variable not found" error. I suspect you are creating this variable somewhere else which is why it is in scope. The statement in the LOAD of the form has nothing to do with it.
>
> Other than that, looks like a case of Dangling Object References.
>
> Try this code in the click method of command2:
> aCalendar[1,1] = .NULL.
> RELEASE aCalendar
> ThisForm.release


Hi Bernard.

Thanks again !! - issuing aCalendar(1,1) = .null. does the trick.

I was expecting Release All to achieve the same result - obviousely not.

Thanks

Deane

ENTIRE THREAD

Objects in an array Posted by Deane Robieson @ 4/18/2006 4:26:05 AM
RE: Objects in an array Posted by Bernard Bout @ 4/18/2006 7:44:14 AM
RE: Objects in an array Posted by Ilya Rabyy @ 4/18/2006 5:24:45 PM
RE: Objects in an array Posted by Deane Robieson @ 4/18/2006 11:43:12 PM
RE: Objects in an array Posted by Deane Robieson @ 4/18/2006 11:19:15 PM