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!

Check if form is loaded 3

Status
Not open for further replies.

BlackDice

Programmer
Mar 1, 2004
257
US
Is there a way I can check to see if a form is already loaded. There's a weird scenario where a form is showing up twice if the user does something a certain way. Is there a way I can see if there is already an instance of the form running before allowing the current one to load?

BlackDice

 
Assuming your forms caption is unique, let call it MyProblemForm, this would be one way.

IF CheckDupForm('MyProblemForm')
DO FORM MyProblemForm
ENDIF

FUNCTION CheckDupForm
LPARAMETERS cCaption
LOCAL lReturn
lReturn = .T.
FOR i = 1 TO _Screen.FormCount
IF _Screen.Forms(i).Caption = cCaption
lReturn = .F.
EXIT
ENDIF
ENDFOR
RETURN lReturn


Regards,
Jim
 
In the init of the form use something like
Code:
local lnForms, i,Retval
lnForms = _screen.formcount
FOR i = lnForms to 1 STEP -1
  if _screen.Forms(i).name='Form1'
  retval = .f.
  else 
   retval = .t.
  endif
ENDFOR
return retval


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
If the form name or the form caption are not guaranteed to be unique you could include either a custom property (with a unique name) or put something unique in the form's tag property. Then just loop through the forms collection as shown by Jim and Mike and check for the unique property or tag string.

boyd.gif

SweetPotato Software Website
My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top