Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i call a form from a prg?

Status
Not open for further replies.

tristero

Programmer
Jan 24, 2003
95
US
i wrote a prg and in the prg i say "DO FORM myform"

myform is a form i built in the form editor to handle output from the prg.

but when i say:
Code:
myform.label1.caption = "hello"

i get an error saying that it cannot find object myform.

what am i missing?

Dan Trenz
Ann Arbor, MI
 
The form has to exist as an object reference...

LOCAL loMyForm
DO FORM myFOrm NAME loMyForm LINKED

If you include the LINKED word, then releasing loMyForm will release the form.
 
Also

It could be because you are referencing the the physical name of the form and not the NAME property.

Open the form and go to the NAME property. It may be different.

Example, assuming the form you open has the NAME property set to boo

boo.label1.caption = "hello"


Jim Osieczonek
Delta Business Group, LLC
 
wgcs: i tried this...
Code:
LOCAL loMyform
DO FORM myform NAME loMyform LINKED 



myform.label1.caption = "hello"
no error this time, but the form didn't open (or it opened and closed really fast)


jimoo: yes the name is myform, as is the file name (myform.scx)

Dan Trenz
Ann Arbor, MI
 
aha, got it... it was opening, i had to put in a WAIT to keep it from releasing the form

thanks guys

Dan Trenz
Ann Arbor, MI
 
If the form was releasing right away then your form isn't modeless (check the WindowType property) and you don't have a Read Events command in your prg after calling the form. You need to have one or the other to keep a form up. (If you use Read Events, make sure you have a corresponding Clear Events in the menu option or button that's supposed to quit the app.)


-BP (Barbara Peisch)
 
...you don't have a Read Events command in your prg after calling the form. You need to have one or the other to keep a form up.

Barbara, I don't think that is true in all cases. I use a few types of forms without the read events. My background, progress, MDI, and a few others.

If we simply type:

DO FORM myform

in the command window - to launch a form that is not set to modal - it comes up and remains up fine until we close it. I think there is something else going on that we don't see. Maybe it is a speed issue, like tristero mentioned, but I have never experienced that type of problem.



Jim Osieczonek
Delta Business Group, LLC
 
tristero

Giving this more thought. My prior comment is true, but where Barbara brings up a point is, "How are you launching that program?"

If you're doing it from the command line, like I mentioned, that is one thing, but if you are doing it in a prg it will continue processing the code after the DO FORM command without the READ EVENTS Barbara mentioned.

It could be a case where the form is loading, but then the code continues and terminates the prg. A snippet of code and a little more description will be helpful if you have not solved the problem.



Jim Osieczonek
Delta Business Group, LLC
 
the final solution...
DO prg from the command window

containing:
Code:
DO FORM c:\myform.scx NAME oForm

oForm.Label1.Caption = "Hello"

The "LINKED" was destroying/releasing the form when the program ended, so it opened and closed very fast.

removing the "LINKED" leaves the form open (like i wanted).

thanks again

Dan Trenz
Ann Arbor, MI
 
Hi Jim,

Yeah, there were a couple of problems with my message. :) For one, I meant to say the form wasn't modal, NOT modeless. I assumed that Dan wasn't launching the form from the Command Window, since it was disappearing on him, but I should have voiced that assumption.


-BP (Barbara Peisch)
 
Yep - After giving it 2nd thought I realized the direction you were heading. It was late and my pea brain was tired.

Jim Osieczonek
Delta Business Group, LLC
 
I'm glad you worked it out, Dan.

In my posting: If you include the LINKED word, then releasing loMyForm will release the form.


The variable loMyForm was, as you have concluded, being released when it went out of scope (when the procedure ended). There are various approaches to avoid this problem, which all depend on your circumstances.

A "READ EVENTS" after launching the form and programmatically adjusting it is one way.

Not using the keyword "LINKED" is another way. However, inside a program, without using the LINKED keyword, once the variable goes out of scope, it's difficult to programmatically reference the form. (of course, it's always available somewhere in _VFP.Forms[...])

Another way would be to make the variable public first:
PUBLIC goMyForm
DO FORM MyForm NAME goMyForm LINKED
..... The form will remain until it is closed or "RELEASE goMyForm" or some other assignment to goMyForm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top