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

Mscal Calendar 7 Question 1

Status
Not open for further replies.

RandyDeWitt

IS-IT--Management
Dec 16, 2002
14
US
I have a question concerning the usage of the calendar control in VFP 7.0. I have created the following container inside of my standard class file.

The behavior I want is to press the down arrow on my container, have the calendar pop up, select a date, then have the calendar disappear.

If I run the code through the debugger, everything appears correct including transferring the value back to date control. It appears that after I transfer the value, then set the visible flag to .F. in the ole control, the calendar disappears then reappears for no apparent reason. I can no longer select a date using the calendar. If I cycle the display button, it operates as expected.

I am at a loss as to why the calendar redisplays after I set Visible = .F. Any insight would be appreciated.

Here is the definition for my date class.

**************************************************
*-- Class: xcntdate (c:\vfp7projects\honda\genclass.vcx)
*-- ParentClass: xcnt (c:\vfp7projects\class\dnuroot.vcx)
*-- BaseClass: container
*-- Time Stamp: 08/01/05 05:02:11 PM
*
DEFINE CLASS xcntdate AS xcnt


Width = 155
Height = 183
BackStyle = 0
BorderWidth = 0
TabStop = .T.
Name = "xcntdate"

*-- Defines the control source for txtDate.
cdatecontrol = .F.


ADD OBJECT txtdate AS xtxt WITH ;
Height = 23, ;
Left = 0, ;
TabIndex = 1, ;
Top = 0, ;
Width = 108, ;
Name = "txtDate"


ADD OBJECT imgdropcal AS ximg WITH ;
Picture = "other\ddlb.bmp", ;
Height = 22, ;
Left = 120, ;
Top = 2, ;
Width = 17, ;
Name = "imgDropCal"


ADD OBJECT olecal AS olecontrol WITH ;
Top = 36, ;
Left = 0, ;
Height = 145, ;
Width = 146, ;
TabIndex = 2, ;
TabStop = .T., ;
Name = "oleCal"


*-- Generic method to show / hide calendar control.
PROCEDURE showcal
*\ Method designed to show or hide the ole calendar control. It examines the
*\ visible property of olecal to decide what to do. If visible, it hides the calendar
*\ if !visible, it shows the calendar.
WITH this
IF .oleCal.Visible
*\ Calendar visible, move value back to txtDate
.txtDate.Value = TTOD(.oleCal.Object.Value)
.oleCal.Enabled = .F.
.oleCal.Visible = .F.
ELSE
*\ Calendar !visible, initialize value from txtDate and display.
.oleCal.Object.Value = .txtDate.Value
.oleCal.refresh()
.oleCal.Enabled = .T.
.oleCal.Visible = .T.
ENDIF
ENDWITH



ENDPROC


PROCEDURE Init
*\ Init method sets the control source for txtDate and initializes lCalVisible
WITH this
.txtDate.ControlSource = .cDateControl
.oleCal.Enabled = .F.
.oleCal.Visible = .F.
.oleCal.Refresh()
ENDWITH
ENDPROC


PROCEDURE txtdate.Refresh
*\ Transfer value to oleCal object.
WITH this
.Parent.oleCal.oBJECT.Value = .Value
.Parent.oleCal.refresh()
ENDWITH
ENDPROC


PROCEDURE txtdate.LostFocus
*\ Transfer value to oleCal object.
WITH this
.Parent.oleCal.oBJECT.Value = .Value
.Parent.oleCal.refresh()
ENDWITH
ENDPROC


PROCEDURE imgdropcal.Click
*\ Show/Hide oleCal control
this.Parent.showcal()
ENDPROC


PROCEDURE olecal.AfterUpdate
*** ActiveX Control Event ***
this.Parent.showcal()
ENDPROC


ENDDEFINE
*
*-- EndDefine: xcntdate
**************************************************
 
Hi Randy.

I am at a loss as to why the calendar redisplays after I set Visible = .F. Any insight would be appreciated.

You need to add the following after this line of code:

.oleCal.Visible = .F.

Code:
***********************************************************************
*** Changed By.: Marcia G. Akins on 25 January 2003
*** Reason.....: It seems that in Win2k and later, the calendar refuses to go away
***********************************************************************
  .OleCal.Height = 0
  .height = .txtDate.Top + .txtDate.Height + 2

Marcia G. Akins
 
I suppose I would be even better if I also mentioned that Randy would have to Save the original Height of both the container and the calendar control in the Init() of the container like this:

Code:
This.AddProperty( [nOriginalHeight], This.Height  )
This.AddProperty( [nOriginalcalendarheight], This.oleCal.Height )

And then in the code that drops the calendar, he will have to add this before making the calendar visible:

Code:
.Height = .nOriginalHeight
.OleCal.Height = .nOriginalCalendarHeight

Marcia G. Akins
 
Don,

You are so right! There is an incredible number of talented people in this forumn. Marcia is certainly amongst the best of them.

Marcia,

I read and re-read your MEgaFox and 1001 Things books as my guideline while I learn this language. I appreciate the help you have provided. It has fixed my problem.

Please don't stop sharing your knowledge with those of us who are still learning this product.

Thank-you

Randy DeWitt
 
Hi Randy.

I read and re-read your MEgaFox and 1001 Things books as my guideline while I learn this language. I appreciate the help you have provided. It has fixed my problem.

The code that you posted looked a bit similar, although modified, to the code in Chapter 4 of 1001 Things ;-)

As a matter of fact, the fix to this problem has been available on the Hentzenwerke web site since January 2003 because that is when one of our readers sent me an e-mail about the same problem that you described here. The code worked when we wrote the book back in 2000 (VFP 6 running under Win98), but it broke on Win2K and later. If you are using any of the classes from the book, you really should check the errata.

Please don't stop sharing your knowledge with those of us who are still learning this product.

Thanks for the kind words. I wouldn't dream of it. It is my way of giving back to the community. There were a lot of people that helped me when I started to learn VFP :)

I find it interesting that you say that the books we wrote helped you, as a beginner, to learn the language. We have never thought of our books as beeing suitable for beginners. As a matter of fact, in the introduction, we state explicitly that the purpose of the book is not to teach you the language, that we expect the reader to have some knowledge aboout the syntax and about building classes.



Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top