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

disappearing modeless form 1

Status
Not open for further replies.

billyhs

Programmer
Jul 28, 2004
11
ID
Hi all,

I'm new in programming Visual FoxPro, and am using version 8.
At the moment I'm encountering the following problem which I can't solve,

I have a top-level form that has one command button named btnMaintain to open another form
using createobject function. When I clicked on that button, that second form showed
up very quickly before it disappeared. It is supposed to display a modeless form.
Has anyone ever encountered the same problem and know how to fix it ?
The codes are listed below.

Thanks for all your help.


* main.prg
IF !FILE('frmTest3.scx')
cCurrentProcedure = SYS(16,1)
nPathStart = AT(":",cCurrentProcedure)- 1
nLenOfPath = RAT("\", cCurrentProcedure) - (nPathStart)
SET DEFAULT TO (SUBSTR(cCurrentProcedure, nPathStart, nLenofPath))
ENDIF

DO FORM frmTest3
READ EVENTS

*------------------------------------------------------------

* testprg1.prg
DEFINE CLASS frmSearch As Form
Caption = 'Search Form'
Left = 2
Top = 2
Width = 100
Height = 100
AutoCenter = .T.
ENDDEFINE

DEFINE CLASS frmSearchChild As frmSearch
Visible = .T.
ADD object txtAddress as Textbox

PROCEDURE Destroy
CLEAR events
ENDPROC

ENDDEFINE

*------------------------------------------------
*Inside frmTest3.scx

procedure Init
Application.Visible = .F.
endproc

procedure Destroy
Application.Visible = .T.
CLEAR EVENTS
thisForm.Release
RELEASE all
endproc

* Inside btnMaintain
procedure Click
SET PROCEDURE TO TestPrg1.prg additive

frmMaintain = CREATEOBJECT("frmSearchChild")
IF TYPE("frmMaintain") = "O" AND !ISNULL(frmMaintain)
frmMaintain.Caption = 'Maintenance'
frmMaintain.Show(2) && modeless
ENDIF
endproc

Note:
If I changed the parameter of Show from 2 to 1 (modal) then the form is displayed properly.
 
Hello BillyHs.

>> When I clicked on that button, that second form showed
up very quickly before it disappeared. It is supposed to display a modeless form. <<

The short answer here is that, because the second form is modeless, code execution does not stop when the DO FORM line in the click of the button is executed. The code continues to run.

If you want execution to pause and ait for the user to deal with the second form, you have to make it modal.

If you want you forms to be modeless, you need to implement something the a form manager to instantiate your forms and hold an object reference to them until they are ready to be released.



Marcia G. Akins
 
Also check ShowWindow and Sesktop properties.

Regards,

Mike
 
The other answers *almost* get you there....

Code:
* Inside btnMaintain
procedure Click
    SET PROCEDURE TO TestPrg1.prg additive

    frmMaintain = CREATEOBJECT("frmSearchChild")
    IF TYPE("frmMaintain") = "O" AND !ISNULL(frmMaintain)
        frmMaintain.Caption = 'Maintenance'
        frmMaintain.Show(2)    && modeless
    ENDIF
endproc

You are creating "frmMaintain" in this code piece, but since it is not modal, execution continues after the statement:
frmMaintain.Show(2) && modeless
Therefore, this private variable "frmMaintain" goes out of scope at the endProc, and the form goes away (is released) along with that variable.

You can do this:
Code:
* Inside btnMaintain
procedure Click
    SET PROCEDURE TO TestPrg1.prg additive
    RELEASE frmMaintain
    PUBLIC frmMaintain
    frmMaintain = CREATEOBJECT("frmSearchChild")
    IF TYPE("frmMaintain") = "O" AND !ISNULL(frmMaintain)
        frmMaintain.Caption = 'Maintenance'
        frmMaintain.Show(2)    && modeless
    ENDIF
endproc
And all is well.

Or, if you don't want globals hanging around, or want to have multiple instances of the same form, do something like this:
Code:
frmMaintain = CREATEOBJECT("frmSearchChild")

* See if the global form list exists yet:
IF TYPE('_screen.myForms')<>'O'
  _screen.AddObject('MyForms','Collection')
ENDIF
* add the new form to the global form collection:
_screen.myForms.Add(frmMaintain)


- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Thank you all for your help.
Now I know what happened and fixed that problem.
Thanks to Bill (wgcs) for giving details in code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top