Subject |
Re: VARIABLE DECLARATION |
From |
Mustansir Ghor <mustan31@hotmail.com> |
Date |
Sun, 11 Mar 2018 08:36:10 -0400 |
Newsgroups |
dbase.getting-started |
Dear Andy
This is real. Great. Thank you. I has cleared many issues.
I had used similar lines in rendering a report that is before render when you put program in memory (set procedure to xyz.rep) and open report class (r = new xyzreport()). After this I could put some of report text like form text by r.pagetemplate1.title.text =form.text
So all in all it means
f = new xyzform()
creates object in memory and windows assigns a handle to it. If xyzform class is not therei n current file then we have to define it by Set procedure to xyz.wfm which loads the program in memory
Thank you
Best Regards
Mustansir
Andy Taylor Wrote:
> Akshat, Mustansir
>
> Let me take you both through form instantiation and variable scope as we run through the code below:
>
> mipdname = "" // the variable mipdname now exists as a private variable within memory
>
> ** END HEADER -- do not remove this line
> // Generated on 07/03/2018
> //
> parameter bModal
> local f // a local memory variable is created
> f = new ghor22Form() // the form now exists in memory as an encapsulated object referred to via f
>
> if (bModal) // assume bModal is false for the moment
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open() // the form opens - this assigns a windows handle to the object and it appears on screen
> endif
>
> At this point the rest of the code in the form is irrelevant, it belongs to the class definition of ghor22Form, it doesn't
> get run... it was run above as part of "f = new ghor22Form()". So we have effectively reached the end of the wfm
> code. In your mind think "return".
>
> Therefore, once the form opens, f, which is local in scope, disappears.
> What about mipdname? Well, that was private in scope and as we have hit a return point on the processing of ghor22.wfm
> it too will disappear.
>
> The only thing left (hanging in memory) is the form. The form can, obviously, no longer see f, mipdname or bModal.
> The reason the form stays in memory is because windows has an open handle to it. Once you close it the form will
> also disappear from memory. This is handled automatically by dBase and works as expected UNLESS your programming
> has managed to insert another memory pointer to that form, in which case it will still exist in memory. That, however, is
> beyond the scope of this discussion.
>
> As Mervyn has said if you insist on using a memory variable which is visible to the form you could start with
> Public mipdname; mipdname = ""
> This would be visible to every object in dBASE, not only the form. It would NOT be private in scope to this form and
> could get messy when opening multiple forms... you'd have to have a different variable name for each form. You also
> have to be sure to release the public variables when the forms close.
>
> The better way to do what you want is to make the midpname variable a property of the form. That way it will disappear
> when the form gets released from memory but remain in scope to the form and only that form. The way to do this easily
> is within the form class definition:
> function onOpen; form.mipdname = ""; return
>
> Note that you cannot write this as:
> function onOpen; mipdname = ""; return
> Why? Because you got to a return point... OnOpen has finished processing and the private variable mipdname disappears from memory....
>
> So the message is stop trying to use memory variables in forms, they don't work the way you think they should unless they
> are part of a method or, for a private variable, a chain of methods.
> Instead of memory variable start thinking "a property of the form is what I need".
>
> Now, turning to Akshat's methods. Akshat duplicates a copy of the bootstrap above the header line and rewrites it knowing
> that the designer won't mess with it. This is a neat trick. Could you write your memory variable in there? Yes. If you move it
> to make it a form property. See below:
>
> parameter bModal
> local f
> f = new ghor22Form()
> f.mipdname = "" // sneaky additional code adds a property before the form is opened.
> if (bModal)
> f.mdi = false // ensure not MDI
> f.readModal()
> else
> f.open()
> endif
>
> ** END HEADER -- do not remove this line
> --designer code follows...
>
> Akshat also notes that his method will work with readmodal() but not open(). This is because with readmodal everything stops,
> no further processing occurs and we don't get to the return point after processing the wfm code until AFTER the readmodal
> form also closes. That is why a readmodal form would also be able to see mipdname and bModal but not, of course, f....
>
> One final point to note is that it does take some time after opening a form for any variables such as mipdname to be released
> from memory. This is why it may be possible to access mipdname using the onOpen event of a form or any code that is triggered
> very quickly. Wait any length of time however and mipdname will not remain accessible in memory. This is probably why
> Mustansir's first method of using mipdname worked and the other two didn't.
>
> I hope this rather long-winded explanation helps (this sort of thing took me long enough to figure out some years ago).
> Andy.
|
|