Discussion:
is this form Open...
(too old to reply)
Ivan Benttini
2008-11-09 23:00:40 UTC
Permalink
/*

Andrew,
where should i put a message that the form is OPEN
since I intent to open the form c:\AB\Password.wfm
before I open this here form(My main form).
and then close the c:\AB\Password.wfm to see if the message
changes to "The form c:\AB\Password.wfm is NOT OPEN"
again
*/

/////////////////////////////////////////////////

_app.aOpenForms = new assocArray() //here is what you mean before the app
start?

/////////////////////////////////////////////////

** END HEADER -- do not remove this line
//
// Generated on 11/09/2008
//
parameter bModal
local f
f = new testformOpenForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class testformOpenForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
onClose = class::FORM_ONCLOSE
height = 16.0
left = 53.0
top = 0.0
width = 40.0
text = ""
endwith

this.RECTANGLE1 = new RECTANGLE(this)
with (this.RECTANGLE1)
left = 9.0
top = 4.0
width = 23.0
height = 1.5
text = "Test if a form is Open"
endwith


function form_onClose
_app.aOpenForms["PasswrdForm"]=false

release object _app.aOpenForms
_app.aOpenForms := null
return

function form_onOpen
_app.aOpenForms["PasswrdForm"]=true
return

endclass
Ivan,
Try the following untested code.
_app.aOpenForms = new assocArray()
_app.aOpenForms["YourUniqueFormName"] = true
_app.aOpenForms["YourUniqueFormName"] = false
release object _app.aOpenForms
_app.aOpenForms := null
regards, andrew
Hi everyOne,
I understanding that checking to see if a form is Open,
the name of the class is to be use and NOT the name of
the form(.wfm), is that Correct?
If that is true, how to extract the CLASS NAME of forms
in a directy (or in a hard drive) and ADD it to an array, so that another
form
can ask, if it is open?
Is a piece of code anywhere with anyone that can be share with me.
"this form is already open, *do this* bla bla bla OR *do that* bla bla
bla..."
Thanks a million,
Ivan
Andrew Shimmin
2008-11-09 21:45:45 UTC
Permalink
Ivan,

Try the following untested code.

When your application starts add:

_app.aOpenForms = new assocArray()

In your form_onOpen event add:

_app.aOpenForms["YourUniqueFormName"] = true

In your form_onClose() event add:

_app.aOpenForms["YourUniqueFormName"] = false

When your application closes add:

release object _app.aOpenForms
_app.aOpenForms := null

regards, andrew
Hi everyOne,
I understanding that checking to see if a form is Open,
the name of the class is to be use and NOT the name of
the form(.wfm), is that Correct?
If that is true, how to extract the CLASS NAME of forms
in a directy (or in a hard drive) and ADD it to an array, so that
another form
can ask, if it is open?
Is a piece of code anywhere with anyone that can be share with me.
"this form is already open, *do this* bla bla bla OR *do that* bla bla
bla..."
Thanks a million,
Ivan
Ivan Benttini
2008-11-10 19:57:14 UTC
Permalink
Andrew,
With "you alls" help I got the result I was lookinf for, many Thanks.
Ivan
Ivan,
Try the following untested code.
_app.aOpenForms = new assocArray()
_app.aOpenForms["YourUniqueFormName"] = true
_app.aOpenForms["YourUniqueFormName"] = false
release object _app.aOpenForms
_app.aOpenForms := null
regards, andrew
Hi everyOne,
I understanding that checking to see if a form is Open,
the name of the class is to be use and NOT the name of
the form(.wfm), is that Correct?
If that is true, how to extract the CLASS NAME of forms
in a directy (or in a hard drive) and ADD it to an array, so that another
form
can ask, if it is open?
Is a piece of code anywhere with anyone that can be share with me.
"this form is already open, *do this* bla bla bla OR *do that* bla bla
bla..."
Thanks a million,
Ivan
Jan Hoelterling
2008-11-09 23:21:00 UTC
Permalink
Hi Ivan,

with the logic Andrew suggested (and which I also use with a slight
variation), you have an AssocArray which you can check for whether your form
is open or not. So, assuming that the classname inside password.wfm is
"PasswordForm", you would first check that it is a key in the array (because
if it never has been opened, it would not exist in the array):

if _app.aOpenForms.iskey("PasswordForm") = true and
_app.aOpenForms["PasswordForm"] = true
?"PasswordForm is open"
else
?"PasswordForm is not open"
endif

The only suggestion I would make is that since the keys in an AssocArray are
case sensitive, I would UPPER them before any access. That way, you won't
run into problems with passwordform vs. PASSWORDFORM

I have also added another reply directly to your message with another method
to ensure a form opens only once.

Hope this helps,

Jan
Jan Hoelterling
2008-11-09 23:26:29 UTC
Permalink
Ivan,

in my application, I have a method called "RunSingle". It checks if a specific form already exists in memory (findinstance), and if so, it sets focus to it (if it's minimized, it gets restored, if it's only instantiated but not opened, it will be opened). If the form does not exist in memory, it is being instantiated and opened. I use this is not so much for checking from one form whether another already exists but more for when the user selects an option from the menu or a toolbar.

This function is called with the Form's Classname as well as the name of the File, for your example, something like

Runsingle("PasswordForm","Password.WFM")

watch for line wrap:
function runsingle
parameter myformname,myformfile
m=findinstance(myformname)
if type("M")="O"
if m.hwnd <> 0 && if it's open
m.open()
else
//avoid minimized call
m.windowstate=iif(m.windowstate=1,0,m.windowstate)
m.setFocus()
endif
m=null
else
mfile = new file()
mfileX = left(_app.exename,rat("\",_app.exename))+left(myformfile,len(myformfile)-1)+"o"
if mfile.exists(mfileX)
myformfile=chr(34)+myformfile+chr(34)
set procedure to &myformfile addi
mfrm=myformname+"()"
newfrm=new &mfrm
newfrm.open()
else
msgbox("Can not find application file:"+chr(13)+;
mfileX,"Error",16)
endif
release mfile
endif
return

Hope this helps,

Jan
Ivan Benttini
2008-11-10 02:27:49 UTC
Permalink
Jan,
I have to work on some thing else now(emergency), but I will report to you
tomorrow I hope, Thanks for quick reply.
Ivan
"Jan Hoelterling" <***@hoelterling.com> wrote in message news:***@news-server...
Ivan,

in my application, I have a method called "RunSingle". It checks if a specific form already exists in memory (findinstance), and if so, it sets focus to it (if it's minimized, it gets restored, if it's only instantiated but not opened, it will be opened). If the form does not exist in memory, it is being instantiated and opened. I use this is not so much for checking from one form whether another already exists but more for when the user selects an option from the menu or a toolbar.

This function is called with the Form's Classname as well as the name of the File, for your example, something like

Runsingle("PasswordForm","Password.WFM")

watch for line wrap:
function runsingle
parameter myformname,myformfile
m=findinstance(myformname)
if type("M")="O"
if m.hwnd <> 0 && if it's open
m.open()
else
//avoid minimized call
m.windowstate=iif(m.windowstate=1,0,m.windowstate)
m.setFocus()
endif
m=null
else
mfile = new file()
mfileX = left(_app.exename,rat("\",_app.exename))+left(myformfile,len(myformfile)-1)+"o"
if mfile.exists(mfileX)
myformfile=chr(34)+myformfile+chr(34)
set procedure to &myformfile addi
mfrm=myformname+"()"
newfrm=new &mfrm
newfrm.open()
else
msgbox("Can not find application file:"+chr(13)+;
mfileX,"Error",16)
endif
release mfile
endif
return

Hope this helps,

Jan
Ivan Benttini
2008-11-10 19:58:08 UTC
Permalink
Jan,
With "you alls" help I got the result I was lookinf for, many Thanks.
Ivan
"Jan Hoelterling" <***@hoelterling.com> wrote in message news:***@news-server...
Ivan,

in my application, I have a method called "RunSingle". It checks if a specific form already exists in memory (findinstance), and if so, it sets focus to it (if it's minimized, it gets restored, if it's only instantiated but not opened, it will be opened). If the form does not exist in memory, it is being instantiated and opened. I use this is not so much for checking from one form whether another already exists but more for when the user selects an option from the menu or a toolbar.

This function is called with the Form's Classname as well as the name of the File, for your example, something like

Runsingle("PasswordForm","Password.WFM")

watch for line wrap:
function runsingle
parameter myformname,myformfile
m=findinstance(myformname)
if type("M")="O"
if m.hwnd <> 0 && if it's open
m.open()
else
//avoid minimized call
m.windowstate=iif(m.windowstate=1,0,m.windowstate)
m.setFocus()
endif
m=null
else
mfile = new file()
mfileX = left(_app.exename,rat("\",_app.exename))+left(myformfile,len(myformfile)-1)+"o"
if mfile.exists(mfileX)
myformfile=chr(34)+myformfile+chr(34)
set procedure to &myformfile addi
mfrm=myformname+"()"
newfrm=new &mfrm
newfrm.open()
else
msgbox("Can not find application file:"+chr(13)+;
mfileX,"Error",16)
endif
release mfile
endif
return

Hope this helps,

Jan
Jan Hoelterling
2008-11-10 21:50:00 UTC
Permalink
You're welcome

Jan
Jan Hoelterling
2008-11-11 00:50:07 UTC
Permalink
Ivan,

I am still not clear on what you are trying to accomplish!?! The function I sent you can easily modified to do something else if the form is not found (look for the ELSE in the "if findinstance" statement). I just don't understand what you need this for!?!

Jan
Ivan Benttini
2008-11-11 01:12:11 UTC
Permalink
Jan,
I am so sorry if I confuse you.
Everything is working the way your function is suppose to work,
When I saw the msgbox= c:\Program Files\dBase\Plus\Bin\xyz.wfo
I could not understand, since I was expecting to see c:\AB\xyz.wfo
OR c:\AB\xyz.wfm in your message box that shows when the selected form xyz
is Not OPEN.
Forgive me for not express my self correctly.
Everything is working fine, THANKS a million.
Ivan

"Jan Hoelterling" <***@hoelterling.com> wrote in message news:***@news-server...
Ivan,

I am still not clear on what you are trying to accomplish!?! The function I sent you can easily modified to do something else if the form is not found (look for the ELSE in the "if findinstance" statement). I just don't understand what you need this for!?!

Jan
Jan Hoelterling
2008-11-11 13:11:21 UTC
Permalink
Hi Ivan,

the path is different in the IDE because it's EXE is the PLUS.EXE which is not the same as the directory you are developing in. Once you compile to EXE, I would imagine that your EXE and the WFO will be in the same directory - at least that's how I do it. If you do this differently, you can remove the check for the object file from the code.

Jan

Greg Hill
2008-11-10 00:12:45 UTC
Permalink
If you don't want to use findinstance() with the class name for some reason.
You can use the adir class to get all the forms from a folder
then use the form name to know the classname as follows:

file name of "start.wfm" = classname "startform"

This is the default way the form designer builds a form. If you are custom building forms just follow that nomenclature and you will have it licked.

If you need help with the adir class let me know.
Greg Hill


"Ivan Benttini" <***@nc.rr.com> wrote in message news:B7vG$***@news-server...

Hi everyOne,

I understanding that checking to see if a form is Open,
the name of the class is to be use and NOT the name of
the form(.wfm), is that Correct?

If that is true, how to extract the CLASS NAME of forms
in a directy (or in a hard drive) and ADD it to an array, so that another form
can ask, if it is open?

Is a piece of code anywhere with anyone that can be share with me.

I try some, but is did not work. I would like to see a message like:
"this form is already open, do this bla bla bla OR do that bla bla bla..."

Thanks a million,
Ivan
Ivan Benttini
2008-11-10 01:35:48 UTC
Permalink
Hi Greg,
Thanks for join in to help me.
This info. about the class name is very good to know,
Thanks for let me know the default way.about the form designer.
Post by Greg Hill
This is the default way the form designer builds a form.
If you are custom building forms
just follow that nomenclature and you will have it licked
If you need help with the adir class let me know
YES and Thanks for offering.

My main goal is programmaticaly from inside of a form, see if an specific form is
open and then send a message to the user to do something.
Would be nice if I could select it from array that populate a listbox.
Anything at all that you can sent me, ( like a piece of code ) if is not much to ask,
At my physical condition an example takes a long way faster.
I greatful to your help and your time.

PS: I don't mind at all to use findinstance()
Ivan
"Greg Hill" <***@hotmail.com> wrote in message news:***@news-server...
If you don't want to use findinstance() with the class name for some reason.
You can use the adir class to get all the forms from a folder
then use the form name to know the classname as follows:

file name of "start.wfm" = classname "startform"

This is the default way the form designer builds a form. If you are custom building forms just follow that nomenclature and you will have it licked.

If you need help with the adir class let me know.
Greg Hill


"Ivan Benttini" <***@nc.rr.com> wrote in message news:B7vG$***@news-server...

Hi everyOne,

I understanding that checking to see if a form is Open,
the name of the class is to be use and NOT the name of
the form(.wfm), is that Correct?

If that is true, how to extract the CLASS NAME of forms
in a directy (or in a hard drive) and ADD it to an array, so that another form
can ask, if it is open?

Is a piece of code anywhere with anyone that can be share with me.

I try some, but is did not work. I would like to see a message like:
"this form is already open, do this bla bla bla OR do that bla bla bla..."

Thanks a million,
Ivan
Greg Hill
2008-11-10 07:55:48 UTC
Permalink
This is very crude but it works.

Caution, the class name inside the form has to be the same as the form designer creates by default. Backup form files will not work, example "backup of start.wfm", because the class name is actually something different.

Paste the follow code into a form file called tester.wfm and save it.

** END HEADER -- do not remove this line
//
// Generated on 11/09/2008
//
parameter bModal
local f
f = new testerForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class testerForm of FORM
with (this)
height = 16.0
left = 82.0
top = 0.0
width = 40.0
text = ""
endwith

this.COMBOBOX1 = new COMBOBOX(this)
with (this.COMBOBOX1)
onChange = class::COMBOBOX1_ONCHANGE
height = 1.0
left = 2.1429
top = 3.0
width = 36.4286
fontSize = 9.0
style = 1 // DropDown
endwith

this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
height = 1.0
left = 1.7143
top = 0.4545
width = 35.4286
text = "refresh array and populate combobox"
fontSize = 9.0
endwith

this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 6.2273
left = 2.0
top = 5.5455
width = 34.0
fontSize = 9.0
text = "<p>When you select a file from the combobox it will open that form if all of the forms dependencies are available.</p><p></p><p></p><p>Give it a shot....</p><p></p><p>Hope this helps</p><p></p>"
endwith


function COMBOBOX1_onChange
cClassName = subs(this.value,1,at('.',this.value)-1)+'form'
cClassName = cClassName.leftTrim().rightTrim()
oClass = findinstance(cClassName)
?cClassname
if empty(oClass)
do (this.value)
else
oClass.setfocus()
endif
return

function PUSHBUTTON1_onClick
tmpFolder = ''
form.aFormFiles = new array()
delspec = tmpFolder+'*.wfm'
Dir_Arr = new array()
Num_Files = Dir_Arr.dirExt(delspec)
for i = 1 to Num_Files
cFile = tmpFolder+Dir_Arr[i,1]
form.aFormFiles.add(cFile)
endfor
form.combobox1.datasource = "array form.aFormFiles"

return

endclass
unknown
2008-11-10 19:02:42 UTC
Permalink
On Mon, 10 Nov 2008 12:39:40 -0500 Ivan Benttini
Sender: "Ivan Benttini" <***@nc.rr.com>
wrote the following in:
Newsgroup: dbase.programming
Thanks Greg, it works fine to select an form from the listbox and open it.
In my code below I kind do the same, but when I open another form that checks to see
if my selection from the listbox is Open or Close, it only return FALSE, I must be missing some.
Can you see it, and correct me, please.
Amend the code as indicated below my signature.

Ivar B. Jessen


//-----
//This function is called to check if a specify
//form is Open(in the system). If the answer is Yes
//it returns TRUE if not it returns FALSE.
func isFormOpen(cFormName)
local oFormRef, nOpened, bRet
bRet = false
cClassName = substr(cFormName, 1, rat(".", cFormName) - 1) + "FORM" // <--- Add line
// oFormRef = FINDINSTANCE(cFormName) // <--- Comment out line
oFormRef = FINDINSTANCE(cClassName) // <--- Add line
if not empty(oFormRef)
if not empty(oFormRef.hWnd)
//-----
Ivan Benttini
2008-11-10 19:54:56 UTC
Permalink
Thanks again for helping me Ivar.
I made the changes you sent me, and it work perfect, just like I was
expecting.
I can not say thank you enough.

"May you live longer and prosper, in good health"
that is not from "Mr.Spok", that is from my father, before I knew
about StartTrek, back home in Prachatta(near Palermo-Italy, population 350
people)
Ivan
Post by unknown
On Mon, 10 Nov 2008 12:39:40 -0500 Ivan Benttini
Newsgroup: dbase.programming
Thanks Greg, it works fine to select an form from the listbox and open it.
In my code below I kind do the same, but when I open another form that checks to see
if my selection from the listbox is Open or Close, it only return FALSE, I
must be missing some.
Can you see it, and correct me, please.
Amend the code as indicated below my signature.
Ivar B. Jessen
//-----
//This function is called to check if a specify
//form is Open(in the system). If the answer is Yes
//it returns TRUE if not it returns FALSE.
func isFormOpen(cFormName)
local oFormRef, nOpened, bRet
bRet = false
cClassName = substr(cFormName, 1, rat(".", cFormName) - 1) + "FORM" // <--- Add line
// oFormRef = FINDINSTANCE(cFormName) // <--- Comment out line
oFormRef = FINDINSTANCE(cClassName) // <--- Add line
if not empty(oFormRef)
if not empty(oFormRef.hWnd)
//-----
Ivan Benttini
2008-11-10 19:58:49 UTC
Permalink
Greg,
With "you alls" help I got the result I was lookinf for, many Thanks.
Ivan
"Greg Hill" <***@hotmail.com> wrote in message news:MjL%***@news-server...
This is very crude but it works.

Caution, the class name inside the form has to be the same as the form designer creates by default. Backup form files will not work, example "backup of start.wfm", because the class name is actually something different.

Paste the follow code into a form file called tester.wfm and save it.

** END HEADER -- do not remove this line
//
// Generated on 11/09/2008
//
parameter bModal
local f
f = new testerForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class testerForm of FORM
with (this)
height = 16.0
left = 82.0
top = 0.0
width = 40.0
text = ""
endwith

this.COMBOBOX1 = new COMBOBOX(this)
with (this.COMBOBOX1)
onChange = class::COMBOBOX1_ONCHANGE
height = 1.0
left = 2.1429
top = 3.0
width = 36.4286
fontSize = 9.0
style = 1 // DropDown
endwith

this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
height = 1.0
left = 1.7143
top = 0.4545
width = 35.4286
text = "refresh array and populate combobox"
fontSize = 9.0
endwith

this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 6.2273
left = 2.0
top = 5.5455
width = 34.0
fontSize = 9.0
text = "<p>When you select a file from the combobox it will open that form if all of the forms dependencies are available.</p><p></p><p></p><p>Give it a shot....</p><p></p><p>Hope this helps</p><p></p>"
endwith


function COMBOBOX1_onChange
cClassName = subs(this.value,1,at('.',this.value)-1)+'form'
cClassName = cClassName.leftTrim().rightTrim()
oClass = findinstance(cClassName)
?cClassname
if empty(oClass)
do (this.value)
else
oClass.setfocus()
endif
return

function PUSHBUTTON1_onClick
tmpFolder = ''
form.aFormFiles = new array()
delspec = tmpFolder+'*.wfm'
Dir_Arr = new array()
Num_Files = Dir_Arr.dirExt(delspec)
for i = 1 to Num_Files
cFile = tmpFolder+Dir_Arr[i,1]
form.aFormFiles.add(cFile)
endfor
form.combobox1.datasource = "array form.aFormFiles"

return

endclass
Greg Hill
2008-11-11 04:47:43 UTC
Permalink
I was out today so I didn't get a chance to followup but I see you got the help you need.
Glad its working.

Your welome.

Greg Hill
"Ivan Benttini" <***@nc.rr.com> wrote in message news:***@news-server...
Greg,
With "you alls" help I got the result I was lookinf for, many Thanks.
Ivan
"Greg Hill" <***@hotmail.com> wrote in message news:MjL%***@news-server...
This is very crude but it works.

Caution, the class name inside the form has to be the same as the form designer creates by default. Backup form files will not work, example "backup of start.wfm", because the class name is actually something different.

Paste the follow code into a form file called tester.wfm and save it.

** END HEADER -- do not remove this line
//
// Generated on 11/09/2008
//
parameter bModal
local f
f = new testerForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class testerForm of FORM
with (this)
height = 16.0
left = 82.0
top = 0.0
width = 40.0
text = ""
endwith

this.COMBOBOX1 = new COMBOBOX(this)
with (this.COMBOBOX1)
onChange = class::COMBOBOX1_ONCHANGE
height = 1.0
left = 2.1429
top = 3.0
width = 36.4286
fontSize = 9.0
style = 1 // DropDown
endwith

this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
height = 1.0
left = 1.7143
top = 0.4545
width = 35.4286
text = "refresh array and populate combobox"
fontSize = 9.0
endwith

this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 6.2273
left = 2.0
top = 5.5455
width = 34.0
fontSize = 9.0
text = "<p>When you select a file from the combobox it will open that form if all of the forms dependencies are available.</p><p></p><p></p><p>Give it a shot....</p><p></p><p>Hope this helps</p><p></p>"
endwith


function COMBOBOX1_onChange
cClassName = subs(this.value,1,at('.',this.value)-1)+'form'
cClassName = cClassName.leftTrim().rightTrim()
oClass = findinstance(cClassName)
?cClassname
if empty(oClass)
do (this.value)
else
oClass.setfocus()
endif
return

function PUSHBUTTON1_onClick
tmpFolder = ''
form.aFormFiles = new array()
delspec = tmpFolder+'*.wfm'
Dir_Arr = new array()
Num_Files = Dir_Arr.dirExt(delspec)
for i = 1 to Num_Files
cFile = tmpFolder+Dir_Arr[i,1]
form.aFormFiles.add(cFile)
endfor
form.combobox1.datasource = "array form.aFormFiles"

return

endclass
Ivan Benttini
2008-11-10 17:39:40 UTC
Permalink
Thanks Greg, it works fine to select an form from the listbox and open it.
In my code below I kind do the same, but when I open another form that checks to see
if my selection from the listbox is Open or Close, it only return FALSE, I must be missing some.
Can you see it, and correct me, please.
** END HEADER -- do not remove this line
//
// Generated on 11/10/2008
//
parameter bModal
local f
f = new is_Form_OpenForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class is_Form_OpenForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
height = 17.5455
left = 53.0
top = 0.0
width = 40.0
text = ""
endwith

this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 1.0
left = 8.0
top = 0.5
width = 25.0
colorNormal = "blue/BtnFace"
fontName = "Times New Roman"
fontBold = true
fontItalic = true
text = "Check to see if a form is OPEN"
endwith

this.TEXT2 = new TEXT(this)
with (this.TEXT2)
height = 1.5
left = 6.0
top = 2.0
width = 28.0
colorNormal = "blue/BtnFace"
fontName = "Times New Roman"
fontBold = true
fontItalic = true
text = "Le't select a form from the listBox below and see if it is open already:"
endwith

this.LISTBOX1 = new LISTBOX(this)
with (this.LISTBOX1)
onSelChange = class::LISTBOX1_ONSELCHANGE
height = 6.0
left = 5.0
top = 3.5
width = 30.0
id = 103
endwith

this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
height = 2.0
left = 5.0
top = 10.0
width = 30.0
text = "Check by clicking here if your selection is already Open"
fontName = "Times New Roman"
fontBold = true
fontItalic = true
borderStyle = 7 // Client
colorNormal = "blue/BtnFace"
endwith

this.TEXT3 = new TEXT(this)
with (this.TEXT3)
height = 1.0
left = 2.0
top = 12.5
width = 19.0
colorNormal = "blue/BtnFace"
fontName = "Times New Roman"
fontBold = true
fontItalic = true
text = "You have selected form: "
endwith

this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
height = 1.0
left = 2.0
top = 13.5
width = 36.0
value = ""
endwith

this.PUSHBUTTON2 = new PUSHBUTTON(this)
with (this.PUSHBUTTON2)
onClick = class::PUSHBUTTON2_ONCLICK
height = 1.0909
left = 30.0
top = 15.5
width = 8.0
text = "Close"
upBitmap = "RESOURCE #750"
borderStyle = 7 // Client
endwith


function LISTBOX1_onSelChange
//I believe the _app. object can be seing thru out the program.
cFormSelected = form.listbox1.value
_app.Selected=cFormSelected
?"Here is your selection: ",_app.Selected
return

function PUSHBUTTON1_onClick
x=form.isFormOpen(_app.Selected) //here we run the isFormOpen() below
?"Selected form from ListBox ",x //with the help of FINDINSTANCE()
if _app.OC = TRUE
form.entryfield1.value = "The form is Open already!"
else
form.entryfield1.value = "Your selection is NOT Open"
endif
return

function PUSHBUTTON2_onClick
form.CLOSE()
return

function form_onOpen
#define NAME 1
#define SIZE 2
#define DATE 3
#define TIME 4
#define ATTR 5

a=new array()
b=new array()
n=a.dir("*.wfm")
for i=1 to n
m=a[i,NAME] //?a[i,NAME]
b.add(m)
endfor
form.listbox1.dataSource="array b"
return

//This function is called to check if a specify
//form is Open(in the system). If the answer is Yes
//it returns TRUE if not it returns FALSE.
func isFormOpen(cFormName)
local oFormRef, nOpened, bRet
bRet = false
oFormRef = FINDINSTANCE(cFormName)
if not empty(oFormRef)
if not empty(oFormRef.hWnd)
bRet = true
oFormRef.CLOSE() //here it closes the oChild form
endif
endif
x = bRet
_app.OC = x
?"Returned by the isFormOpen() using the FINDINSTANCE",_app.OC
return bRet

endclass

"Greg Hill" <***@hotmail.com> wrote in message news:MjL%***@news-server...
This is very crude but it works.

Caution, the class name inside the form has to be the same as the form designer creates by default. Backup form files will not work, example "backup of start.wfm", because the class name is actually something different.

Paste the follow code into a form file called tester.wfm and save it.

** END HEADER -- do not remove this line
//
// Generated on 11/09/2008
//
parameter bModal
local f
f = new testerForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class testerForm of FORM
with (this)
height = 16.0
left = 82.0
top = 0.0
width = 40.0
text = ""
endwith

this.COMBOBOX1 = new COMBOBOX(this)
with (this.COMBOBOX1)
onChange = class::COMBOBOX1_ONCHANGE
height = 1.0
left = 2.1429
top = 3.0
width = 36.4286
fontSize = 9.0
style = 1 // DropDown
endwith

this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_ONCLICK
height = 1.0
left = 1.7143
top = 0.4545
width = 35.4286
text = "refresh array and populate combobox"
fontSize = 9.0
endwith

this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 6.2273
left = 2.0
top = 5.5455
width = 34.0
fontSize = 9.0
text = "<p>When you select a file from the combobox it will open that form if all of the forms dependencies are available.</p><p></p><p></p><p>Give it a shot....</p><p></p><p>Hope this helps</p><p></p>"
endwith


function COMBOBOX1_onChange
cClassName = subs(this.value,1,at('.',this.value)-1)+'form'
cClassName = cClassName.leftTrim().rightTrim()
oClass = findinstance(cClassName)
?cClassname
if empty(oClass)
do (this.value)
else
oClass.setfocus()
endif
return

function PUSHBUTTON1_onClick
tmpFolder = ''
form.aFormFiles = new array()
delspec = tmpFolder+'*.wfm'
Dir_Arr = new array()
Num_Files = Dir_Arr.dirExt(delspec)
for i = 1 to Num_Files
cFile = tmpFolder+Dir_Arr[i,1]
form.aFormFiles.add(cFile)
endfor
form.combobox1.datasource = "array form.aFormFiles"

return

endclass
Andrew Shimmin
2008-11-10 08:35:58 UTC
Permalink
Ivan,
Post by Ivan Benttini
Andrew,
where should i put a message that the form is OPEN
since I intent to open the form c:\AB\Password.wfm
before I open this here form(My main form).
and then close the c:\AB\Password.wfm to see if the message
changes to "The form c:\AB\Password.wfm is NOT OPEN"
again
I see Jan answered your question.

regards, andrew
Loading...