I am trying to implement the solution from
Better Date\Datetime Controls
faq184-3913
and am having a little trouble. The problem is that during runtime, the calendar just flashes up and then disappears. In the development environment, it works flawlessly. I'm thinking it is something obvious that I am just overlooking. Here is the code from the classes. Any help is appreciated - I'd really like to use this solution.
**************************************************
*-- Class: clsdate (c:\cts_service\libs\cts_service_app.vcx)
*-- ParentClass: control
*-- BaseClass: control
*-- Time Stamp: 08/05/08 07:35:10 AM
*
DEFINE CLASS clsdate AS control
Width = 98
Height = 24
BackStyle = 0
SpecialEffect = 1
BackColor = RGB(255,255,255)
*-- Specifies the source of data to which an object is bound.
controlsource = .F.
*-- Specifies the current state of a control.
value = .F.
Name = "clsdate"
ADD OBJECT txtdate AS textbox WITH ;
Alignment = 3, ;
BorderStyle = 0, ;
Value = {}, ;
Height = 21, ;
Left = 1, ;
Margin = 3, ;
SpecialEffect = 1, ;
Top = 1, ;
Width = 73, ;
NullDisplay = " ", ;
Name = "txtDate"
ADD OBJECT cmdcalendar AS commandbutton WITH ;
Top = 1, ;
Left = 73, ;
Height = 22, ;
Width = 24, ;
Picture = "..\..\vfp9\graphics\bitmaps\assorted\calendar.bmp", ;
Caption = "", ;
TabStop = .F., ;
Name = "cmdCalendar"
PROCEDURE value_access
*To do: Modify this routine for the Access method
RETURN THIS.txtDate.Value
ENDPROC
PROCEDURE value_assign
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
THIS.txtDate.value = m.vNewVal
ENDPROC
PROCEDURE controlsource_access
*To do: Modify this routine for the Access method
RETURN THIS.CONTROLSOURCE
ENDPROC
PROCEDURE controlsource_assign
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
THIS.CONTROLSOURCE = m.vNewVal
ENDPROC
PROCEDURE poscalendar
LPARAMETERS loCalendar
WITH loCalendar
IF THISFORM.WINDOWTYPE = 0 && Host form is Modeless
.TOP = OBJTOCLIENT( THIS, 1 ) + SYSMETRIC(9) + this.txtDate.HEIGHT + ;
IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(4), SYSMETRIC(13) ) + ;
IIF( THISFORM.SHOWWINDOW = 2, THISFORM.TOP, OBJTOCLIENT( THISFORM, 1 ) ) + 3 && if there is a menu: + SYSMETRIC(20)
.LEFT = OBJTOCLIENT( THIS, 2 ) + IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(3), SYSMETRIC(12) ) + ;
IIF( THISFORM.SHOWWINDOW = 2, THISFORM.LEFT, OBJTOCLIENT( THISFORM, 2 ) )
IF ( ( .TOP + .HEIGHT ) > SYSMETRIC(2) ) && Adjust to "drop up" if
.TOP = .TOP - .HEIGHT - this.txtDate.HEIGHT - ( 2 * SYSMETRIC(13) ) && near bottom of screen
ENDIF
ELSE && Host form is Modal
.TOP = OBJTOCLIENT( THIS, 1 ) + this.txtDate.HEIGHT + SYSMETRIC(9) + ;
IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(4), SYSMETRIC(13) ) + ;
THISFORM.TOP + 3 && if there is a menu: + SYSMETRIC(20)
.LEFT = OBJTOCLIENT( THIS, 2 ) + IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(3), SYSMETRIC(12) ) + ;
THISFORM.LEFT
IF ( ( .TOP + .HEIGHT ) > _VFP.HEIGHT ) && Adjust to "drop up" if
.TOP = .TOP - .HEIGHT - this.txtDate.HEIGHT - ( 2 * SYSMETRIC(13) ) && near bottom of screen
ENDIF
ENDIF
DO CASE && Shift horizontal position if close to right edge
CASE .SHOWWINDOW = 0 && In Screen
IF .LEFT + .WIDTH > _VFP.WIDTH
.LEFT = 4 + .LEFT - .WIDTH + this.txtDate.WIDTH - 2 * SYSMETRIC(3)
ENDIF
CASE .SHOWWINDOW = 1 && In Top-Level Form
IF .LEFT + .WIDTH > THISFORM.WIDTH
.LEFT = 4 + .LEFT - .WIDTH + this.txtDate.WIDTH - 2 * SYSMETRIC(3)
ENDIF
CASE .SHOWWINDOW = 2 && Top-Level Form
IF .LEFT + .WIDTH > SYSMETRIC(1)
.LEFT = 4 + .LEFT - .WIDTH + this.txtDate.WIDTH - 2 * SYSMETRIC(3)
ENDIF
ENDCASE
ENDWITH
ENDPROC
PROCEDURE Refresh
this.txtDate.Refresh()
ENDPROC
PROCEDURE Init
IF !EMPTY(this.controlsource)
this.txtDate.ControlSource = this.controlsource
ELSE
this.txtDate.value = {}
ENDIF
ENDPROC
PROCEDURE cmdcalendar.Click
LOCAL ldHoldDate
Public gdSelectedDate, goCalendar
IF EMPTY(this.Parent.txtDate.value) .OR. ISNULL(this.Parent.txtDate.value)
gdSelectedDate = DATE()
ELSE
gdSelectedDate = this.Parent.txtDate.value
ENDIF
ldHoldDate = gdSelectedDate
goCalendar = NewObject([clsCalendar],[\libs\cts_service_app],"",gdSelectedDate)
***goCalendar = CREATEOBJECT("clsCalendar",gdSelectedDate)
this.Parent.PosCalendar(goCalendar)
goCalendar.visible = .t.
READ EVENTS
IF ldHoldDate != gdSelectedDate
WITH this.parent
.txtDate.Value = gdSelectedDate
.txtDate.refresh()
ENDWITH
ENDIF
goCalendar = NULL
RELEASE gdSelectedDate, goCalendar
ENDPROC
ENDDEFINE
*
*-- EndDefine: clsdate
**************************************************
**************************************************
*-- Class: clscalendar (c:\cts_service\libs\cts_service_app.vcx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 08/07/08 01:45:13 PM
*
DEFINE CLASS clscalendar AS form
Top = 0
Left = 0
Height = 177
Width = 194
ShowWindow = 2
ShowInTaskBar = .F.
DoCreate = .T.
ShowTips = .T.
BorderStyle = 1
Caption = " "
ControlBox = .F.
Closable = .F.
TitleBar = 0
WindowType = 1
AlwaysOnTop = .T.
BackColor = RGB(255,255,255)
ContinuousScroll = .F.
Themes = .F.
Name = "clscalendar"
ADD OBJECT olecontrol1 AS olecontrol WITH ;
Top = 0, ;
Left = 0, ;
Height = 100, ;
Width = 100, ;
Name = "Olecontrol1"
PROCEDURE Deactivate
CLEAR EVENTS
ENDPROC
PROCEDURE Init
LPARAMETERS tlDate
WITH this.olecontrol1
.day = DAY(tlDate)
.month = MONTH(tlDate)
.year = YEAR(tlDate)
.Width = this.Width
.height = this.height
ENDWITH
ENDPROC
PROCEDURE olecontrol1.DATECLICK
*** ActiveX Control Event ***
LPARAMETERS ttdateclicked
gdSelectedDate = TTOD(ttdateclicked)
CLEAR EVENTS
ENDPROC
ENDDEFINE
*
*-- EndDefine: clscalendar
**************************************************
Ed
Better Date\Datetime Controls
faq184-3913
and am having a little trouble. The problem is that during runtime, the calendar just flashes up and then disappears. In the development environment, it works flawlessly. I'm thinking it is something obvious that I am just overlooking. Here is the code from the classes. Any help is appreciated - I'd really like to use this solution.
**************************************************
*-- Class: clsdate (c:\cts_service\libs\cts_service_app.vcx)
*-- ParentClass: control
*-- BaseClass: control
*-- Time Stamp: 08/05/08 07:35:10 AM
*
DEFINE CLASS clsdate AS control
Width = 98
Height = 24
BackStyle = 0
SpecialEffect = 1
BackColor = RGB(255,255,255)
*-- Specifies the source of data to which an object is bound.
controlsource = .F.
*-- Specifies the current state of a control.
value = .F.
Name = "clsdate"
ADD OBJECT txtdate AS textbox WITH ;
Alignment = 3, ;
BorderStyle = 0, ;
Value = {}, ;
Height = 21, ;
Left = 1, ;
Margin = 3, ;
SpecialEffect = 1, ;
Top = 1, ;
Width = 73, ;
NullDisplay = " ", ;
Name = "txtDate"
ADD OBJECT cmdcalendar AS commandbutton WITH ;
Top = 1, ;
Left = 73, ;
Height = 22, ;
Width = 24, ;
Picture = "..\..\vfp9\graphics\bitmaps\assorted\calendar.bmp", ;
Caption = "", ;
TabStop = .F., ;
Name = "cmdCalendar"
PROCEDURE value_access
*To do: Modify this routine for the Access method
RETURN THIS.txtDate.Value
ENDPROC
PROCEDURE value_assign
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
THIS.txtDate.value = m.vNewVal
ENDPROC
PROCEDURE controlsource_access
*To do: Modify this routine for the Access method
RETURN THIS.CONTROLSOURCE
ENDPROC
PROCEDURE controlsource_assign
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
THIS.CONTROLSOURCE = m.vNewVal
ENDPROC
PROCEDURE poscalendar
LPARAMETERS loCalendar
WITH loCalendar
IF THISFORM.WINDOWTYPE = 0 && Host form is Modeless
.TOP = OBJTOCLIENT( THIS, 1 ) + SYSMETRIC(9) + this.txtDate.HEIGHT + ;
IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(4), SYSMETRIC(13) ) + ;
IIF( THISFORM.SHOWWINDOW = 2, THISFORM.TOP, OBJTOCLIENT( THISFORM, 1 ) ) + 3 && if there is a menu: + SYSMETRIC(20)
.LEFT = OBJTOCLIENT( THIS, 2 ) + IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(3), SYSMETRIC(12) ) + ;
IIF( THISFORM.SHOWWINDOW = 2, THISFORM.LEFT, OBJTOCLIENT( THISFORM, 2 ) )
IF ( ( .TOP + .HEIGHT ) > SYSMETRIC(2) ) && Adjust to "drop up" if
.TOP = .TOP - .HEIGHT - this.txtDate.HEIGHT - ( 2 * SYSMETRIC(13) ) && near bottom of screen
ENDIF
ELSE && Host form is Modal
.TOP = OBJTOCLIENT( THIS, 1 ) + this.txtDate.HEIGHT + SYSMETRIC(9) + ;
IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(4), SYSMETRIC(13) ) + ;
THISFORM.TOP + 3 && if there is a menu: + SYSMETRIC(20)
.LEFT = OBJTOCLIENT( THIS, 2 ) + IIF( THISFORM.BORDERSTYLE = 3, SYSMETRIC(3), SYSMETRIC(12) ) + ;
THISFORM.LEFT
IF ( ( .TOP + .HEIGHT ) > _VFP.HEIGHT ) && Adjust to "drop up" if
.TOP = .TOP - .HEIGHT - this.txtDate.HEIGHT - ( 2 * SYSMETRIC(13) ) && near bottom of screen
ENDIF
ENDIF
DO CASE && Shift horizontal position if close to right edge
CASE .SHOWWINDOW = 0 && In Screen
IF .LEFT + .WIDTH > _VFP.WIDTH
.LEFT = 4 + .LEFT - .WIDTH + this.txtDate.WIDTH - 2 * SYSMETRIC(3)
ENDIF
CASE .SHOWWINDOW = 1 && In Top-Level Form
IF .LEFT + .WIDTH > THISFORM.WIDTH
.LEFT = 4 + .LEFT - .WIDTH + this.txtDate.WIDTH - 2 * SYSMETRIC(3)
ENDIF
CASE .SHOWWINDOW = 2 && Top-Level Form
IF .LEFT + .WIDTH > SYSMETRIC(1)
.LEFT = 4 + .LEFT - .WIDTH + this.txtDate.WIDTH - 2 * SYSMETRIC(3)
ENDIF
ENDCASE
ENDWITH
ENDPROC
PROCEDURE Refresh
this.txtDate.Refresh()
ENDPROC
PROCEDURE Init
IF !EMPTY(this.controlsource)
this.txtDate.ControlSource = this.controlsource
ELSE
this.txtDate.value = {}
ENDIF
ENDPROC
PROCEDURE cmdcalendar.Click
LOCAL ldHoldDate
Public gdSelectedDate, goCalendar
IF EMPTY(this.Parent.txtDate.value) .OR. ISNULL(this.Parent.txtDate.value)
gdSelectedDate = DATE()
ELSE
gdSelectedDate = this.Parent.txtDate.value
ENDIF
ldHoldDate = gdSelectedDate
goCalendar = NewObject([clsCalendar],[\libs\cts_service_app],"",gdSelectedDate)
***goCalendar = CREATEOBJECT("clsCalendar",gdSelectedDate)
this.Parent.PosCalendar(goCalendar)
goCalendar.visible = .t.
READ EVENTS
IF ldHoldDate != gdSelectedDate
WITH this.parent
.txtDate.Value = gdSelectedDate
.txtDate.refresh()
ENDWITH
ENDIF
goCalendar = NULL
RELEASE gdSelectedDate, goCalendar
ENDPROC
ENDDEFINE
*
*-- EndDefine: clsdate
**************************************************
**************************************************
*-- Class: clscalendar (c:\cts_service\libs\cts_service_app.vcx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 08/07/08 01:45:13 PM
*
DEFINE CLASS clscalendar AS form
Top = 0
Left = 0
Height = 177
Width = 194
ShowWindow = 2
ShowInTaskBar = .F.
DoCreate = .T.
ShowTips = .T.
BorderStyle = 1
Caption = " "
ControlBox = .F.
Closable = .F.
TitleBar = 0
WindowType = 1
AlwaysOnTop = .T.
BackColor = RGB(255,255,255)
ContinuousScroll = .F.
Themes = .F.
Name = "clscalendar"
ADD OBJECT olecontrol1 AS olecontrol WITH ;
Top = 0, ;
Left = 0, ;
Height = 100, ;
Width = 100, ;
Name = "Olecontrol1"
PROCEDURE Deactivate
CLEAR EVENTS
ENDPROC
PROCEDURE Init
LPARAMETERS tlDate
WITH this.olecontrol1
.day = DAY(tlDate)
.month = MONTH(tlDate)
.year = YEAR(tlDate)
.Width = this.Width
.height = this.height
ENDWITH
ENDPROC
PROCEDURE olecontrol1.DATECLICK
*** ActiveX Control Event ***
LPARAMETERS ttdateclicked
gdSelectedDate = TTOD(ttdateclicked)
CLEAR EVENTS
ENDPROC
ENDDEFINE
*
*-- EndDefine: clscalendar
**************************************************
Ed