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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form not found in compiled program but found in Project mode

Status
Not open for further replies.

jquerry

Programmer
May 15, 2008
2
US
Hello, all!

I'm having an issue with a program in VFP 9 SP2. I'm writing a program that has a main form ( called "frmMain"). This form has buttons which call other forms.

What I'm trying to do is this - when a user clicks a button (we'll use "CSV to DBF" as my example), this is what will happen:

In frmMain, this code is called by clicking that button:
1. frmMain.visible = .f.
2. do frmCsv2dbf

The called form "frmCsv2dbf" then does its thing. In the form's Release property, I have the following line:
frmMain.visible = .t.

As you can see, I'm trying to make the main form invisible while the other form does its work, then bring its visibility back once the other form is finished.

However, I've hit a bit of a snag. This works flawlessly if I choose "run" while I'm modifying the Project itself. When I Build an exe and run that exe, it does not work. frmMain does lose its visibiliy. frmCsv2dbf does run. But when frmCsv2dbf tries to set frmMain visibility to .t., I get an error message stating that FRMMAIN is not found.

Any ideas as to why this is happening and how I can fix it?

Thanks!
 
My guess is that the first form still exists, but the variable which holds its reference has gone out of scope.

If that's right, the solution depends on how you are instantiating frmMain. If you do something like this:

DO FORM frmMain

then this will create a variable called frmMain which holds a reference to the form. By default, the variable is local to the procedure in which it is created (that is, the procedure containing the DO FORM command). Once that procedure has finished running, the variable will no longer exist, so the code in the second's form's Release (frmMain.visible = .t.) won't find the form.

A quick and dirty solution would be:

PUBLIC goMain
DO FORM frmMain NAME goMain

The, in the second form's Release:

goMain.visible = .t.

Using public variables is not ideal, but this will at least tell us if my diagnosis is correct. I suggest you try the above, and if it works, we can look for longer-term solution.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

Thanks for your response. That did indeed clear it up! Now frmMain becomes visible once again after frmCsv2dbf is released.
 
jquerry,

If you want a longer-term solution...one that I've used is to send an object reference for frmMain to frmCsv2dbf, something like this:
Code:
DO FORM frmCsv2dbf WITH THIS
The Init event of frmCsv2dbf would need to have lines something like
Code:
LPARAMETERS CallingForm
THISFORM.CallingForm = CallingForm
The, in frmCsv2dbf's Release:
Code:
THISFORM.CallingForm.visible = .t.

Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top