Hi
Start a new modeless Form and add 2 buttons, name them Modal and Modeless
In the Valid of Model insert this code
Code:
ThisForm.Hide()
ThisForm.Show(1) && Show Modal
ThisForm.Show(2) && Show Modeless
In the Valid of Modeless insert this code
It may look strange to show modal and modeless in the same valid event of Modal button, but the trick is
When you switch the state of a form from Modeless to Modal at this time you form will be in a wait state meaning
this line of code
Code:
ThisForm.Show(2) && Show Modeless
will never be executed unless you break this wait state and this is what is HIDE() in the other valid doing.
To make this more clear, lets write the first valid like that
Code:
ThisForm.Hide()
ThisForm.Show(1) && Show Modal
WIAT WIND "Hi there"
ThisForm.Show(2) && Show Modeless
When you click this command your form will be Modal and will enter a wait state waiting for your user to communicate with the GUI, but you will never see the wait window unless you click the Modeless button to break the wait state. At this time the rest of you code will be executed which is a wait window and command to FOX to show this form Modeless.
Anyway, one drawback of (of many)for this solution is that your form will flash very quickly according to the Hide().
if you decided to take this as a solution, your problem will be find a method in this ActiveX control suitable to execute the Modal method
and another one for modeless. Although this will work and basically answer your q about switching state but
if I were you I will never do that and deliver my form to the users after I spent the last 2000 years developing and debugging with this ugly flashing thing. Beside it doesn’t look like a clean solution to me.
Meaning I will have to repeat the same game over and over every time I want to use this control in any form and clutter your form with a lot of code. IF some day I want to fix a bug or make enhancement, good luck.
Well, the problem is this spoiled ActiveX control needs its container to be modal, [you said so].
Our problem is, we don't want to switch state of our form
we want to keep it as it is.
Ok, let’s cheat and lie -WOW-, I mean God forgive us all.
We will convince this control that its container is modal but at the same time we will keep our form modeless. How?? Very simple
The idea is to define a Visual class library PopCal.VCX and add two classes to it.
1-Class popup_Calendar based on FORM which will contain the ActiveX control contained in a MODAL FROM.
2-Class cmd_date based on command button, which will call popup_Calendar
Start modifying the first class which is the form. Add a Month View control to this form, change the name of this control to OleCalendar, right click this control and select properties, make sure you set the right propertied for your control like the Start Of Week etc…
Set your form to be Modal (technically, you don’t have to). In the Init of your form add this code
Code:
*// Let the form decide its proper size automatically.
THIS.WIDTH=THISFORM.OleCalendar.WIDTH
THIS.HEIGHT=THISFORM.OleCalendar. HEIGHT
In the DateDblClick of the ActiveX control add this code
Code:
*// The Parent object in the next line of code references the container of the ActiveX control
*// Which is your modal form. ReturnSelecteDate() is a method you will add to this form
THIS.PARENT.ReturnSelecteDate()
THIS.PARENT.HIDE()
Now you need to add one method and one property to your form (the container of the ActiveX control)
ReturnSelecteDate method and SelectedDate property
Now open the ReturnSelecteDate and insert this code
Code:
LOCAL lcDate,lcMonth,lcDay,lcYear
lcMonth = ALLTRIM(STR(THIS.OleCalendar.Month,2))
lcDay = ALLTRIM(STR(THIS.OleCalendar.Day,2))
lcYear = ALLTRIM(STR(THIS.OleCalendar.Year,4))
lcDate = '{^'+ lcYear + '-' + lcMonth + '-' + lcDay + '}'
THIS.SelectedDate = &lcDate
Now this class is done, you can test drive it from your command window
Code:
SET CLASSLIBRARY TO GETFILE() &&Locate your PopCal.VCX file
OX=CREATEOBJECT(“Popup_Calendar”)
OX.SHOW(1) && SHOW AS MODAL, THAT IS WHY (technically, you don’t have to)
*// Now Dbl click any date you want, the calendar will disappear
WAIT WIND DTOC(OX.SelectedDate)
OX=NULL
Very simple, so much fun. Now it is the time for the real work, although you can call this calendar from any form just like what you did from your command window, as a programmer you still want to feel more control over this calendar, right?
Some thing like a command button in my form has a connection with the text box, when I click this button I will have my calendar in the right position and I don’t need to worry about any thing(after I already did).
Well, you can go ahead and add the cmd_Date class to you PopCal.VCX class library
Code:
CREATE CLASS cmd_date OF PopCal AS COMMANDBUTTON
Why is this command button for???
1- Instantiate an instance of the popup_calendar class.
2- Automatically position the calendar properly relative to the associated object (The text box we will update its value with whatever returned date).
3- If any valid date in the associated object, initialize the calendar with this date.
4- When the calendar is closed update the associated object.
5- Destroy the instance of this calendar.
Since this is a lot of code and I want to run to my bed before I collapse. I will leave the implementation of this command button to you or if you want the class library, feel free to send me E-mail and I will send to you.
Hope this will help
Walid Magd
Engwam@Hotmail.com