| **Navigation:**  [[templates.htm|Templates]] > [[tlrcontents.htm|Template Language Reference]] > Annotated Examples > Extension Template: DateTimeDisplay >====== Extension Template: DateTimeDisplay {{c6h0068.jpg|C6H0068.jpg}} ====== | [[control template dosfilelookup.htm|{{btn_prev_n.gif|Previous page}}]][[tlrcontents.htm|{{btn_home_n.gif|Return to chapter overview}}]][[ datetimedisplaycode group.htm|{{btn_next_n.gif|Next page}}]] | | || The //DateTimeDisplay// Extension template displays the date and/or time in either a display-only STRING control or a section of the status bar. Of course, the status bar should be declared on the window. **#EXTENSION(DateTimeDisplay,'Display the date and/or time in the current window') %|** **          ,HLP('~TPLExtensionDateTimeDisplay'),PROCEDURE** **#BUTTON('Date and Time Display'),AT(10,,180)** **  #BOXED('Date Display...')** **    #PROMPT('Display the current day/date in the window',CHECK) %|** **           ,%DisplayDate,DEFAULT(0),AT(10,,150)** **    #ENABLE(%DisplayDate)           ** **      #PROMPT('Date Picture:',DROP('October 31, 1959|OCT 31,1959|10/31/59| %|** **                                10/31/1959|31 OCT 59|31 OCT 1959|31/10/59| %|** **                                          31/10/1959|Other')),%DatePicture %|** **                                   ,DEFAULT('October 31, 1959')** **      #ENABLE(%DatePicture = 'Other')** **        #PROMPT('Other Date Picture:',@S20),%OtherDatePicture,REQ** **      #ENDENABLE** **      #PROMPT('Show the day of the week before the date',CHECK),%ShowDayOfWeek %|** **              ,DEFAULT(1),AT(10,,150)** **      #PROMPT('&Location of Date Display:',DROP('Control|Status Bar')) %|** **              ,%DateDisplayLocation** **      #ENABLE(%DateDisplayLocation='Status Bar')** **        #PROMPT('Status Bar Section:',@n1),%DateStatusSection,REQ,DEFAULT(1)** **      #ENDENABLE** **      #ENABLE(%DateDisplayLocation='Control')** **        #PROMPT('Date Display Control:',CONTROL),%DateControl,REQ** **      #ENDENABLE** **    #ENDENABLE** **  #ENDBOXED** **  #BOXED('Time Display...')** **    #PROMPT('Display the current time in the window',CHECK),%DisplayTime %|** **            ,DEFAULT(0),AT(10,,150)** **    #ENABLE(%DisplayTime)           ** **      #PROMPT('Time Picture:',DROP('5:30PM|5:30:00PM|17:30|17:30:00| %|** **                                   1730|173000|Other')),%TimePicture %|** **                                   ,DEFAULT('5:30PM')** **      #ENABLE(%TimePicture = 'Other')** **        #PROMPT('Other Time Picture:',@S20),%OtherTimePicture,REQ** **      #ENDENABLE** **      #PROMPT('&Location of Time Display:',DROP('Control|Status Bar')) %|** **              ,%TimeDisplayLocation** **      #ENABLE(%TimeDisplayLocation='Status Bar')** **        #PROMPT('Status Bar Section:',@n1),%TimeStatusSection,REQ,DEFAULT(2)** **      #ENDENABLE** **      #ENABLE(%TimeDisplayLocation='Control')** **        #PROMPT('Time Display Control:',CONTROL),%TimeControl,REQ** **      #ENDENABLE** **    #ENDENABLE** **  #ENDBOXED** **#ENDBUTTON** **#ATSTART** **  #DECLARE(%TimerEventGenerated)** **  #IF(%DisplayDate)** **    #DECLARE(%DateUsePicture)** **    #CASE(%DatePicture)** **    #OF('10/31/59')** **      #SET(%DateUsePicture,'@D1')** **    #OF('10/31/1959')** **      #SET(%DateUsePicture,'@D2')** **    #OF('OCT 31,1959')** **      #SET(%DateUsePicture,'@D3')** **    #OF('October 31, 1959')** **      #SET(%DateUsePicture,'@D4')** **    #OF('31/10/59')** **      #SET(%DateUsePicture,'@D5')** **    #OF('31/10/1959')** **      #SET(%DateUsePicture,'@D6')** **    #OF('31 OCT 59')** **      #SET(%DateUsePicture,'@D7')** **    #OF('31 OCT 1959')** **      #SET(%DateUsePicture,'@D8')** **    #OF('Other')** **      #SET(%DateUsePicture,%OtherDatePicture)** **    #ENDCASE** **  #ENDIF** **  #IF(%DisplayTime)** **    #DECLARE(%TimeUsePicture)** **    #CASE(%TimePicture)** **    #OF('17:30')** **      #SET(%TimeUsePicture,'@T1')** **    #OF('1730')** **      #SET(%TimeUsePicture,'@T2')** **    #OF('5:30PM')** **      #SET(%TimeUsePicture,'@T3')** **    #OF('17:30:00')** **      #SET(%TimeUsePicture,'@T4')** **    #OF('173000')** **      #SET(%TimeUsePicture,'@T5')** **    #OF('5:30:00PM')** **      #SET(%TimeUsePicture,'@T6')** **    #OF('Other')** **      #SET(%TimeUsePicture,%OtherTimePicture)** **    #ENDCASE** **  #ENDIF** **#ENDAT** **#AT(%DataSectionBeforeWindow)** **  #IF(%DisplayDate AND %ShowDayOfWeek)** **DisplayDayString STRING('Sunday   Monday   Tuesday  WednesdayThursday %|** **                         Friday   Saturday ')** **DisplayDayText   STRING(9),DIM(7),OVER(DisplayDayString)** **  #ENDIF** **#ENDAT** **#AT(%BeforeAccept)** **  #IF(%DisplayTime OR %DisplayDate)** **IF NOT INRANGE(%Window{Prop:Timer},1,100)** **  %Window{Prop:Timer} = 100** **END** **#INSERT(%DateTimeDisplayCode)** **  #ENDIF** **#ENDAT** **#AT(%WindowEventHandling,'Timer')** **  #SET(%TimerEventGenerated,%True)** **  #IF(%DisplayDate OR %DisplayTime)** **#INSERT(%DateTimeDisplayCode)** **  #ENDIF** **#ENDAT** **#AT(%WindowOtherEventHandling)** **  #IF(%DisplayDate OR %DisplayTime)** **    #IF(NOT %TimerEventGenerated)** **IF EVENT() = EVENT:Timer** **  #INSERT(%DateTimeDisplayCode)** **END** **    #ENDIF** **  #ENDIF** **#ENDAT** An Extension template starts with the #EXTENSION statement. The PROCEDURE attribute specifies the Extension template is available only at the procedure level, not the global level of the application. The #BUTTON structure creates a separate page for all the prompts for this Extension template. These prompts ask the programmer for the format of the date and/or time to display, and whether to display them in a control or the status bar. The #ATSTART statement begins a section of template code that executes before any source code generates for the procedure. This means it is only appropriate to initialize user-defined template symbols and perfrom any necessary set up to generate correct source for the control template into the procedure. This section does not generate source code. The #DECLARE(%TimerEventGenerated) statement declares a symbol used only in this Extension template. It is used to flag whether an OF EVENT:Timer clause has been generated for the procedure. The #IF(%DisplayDate) structure sets up to display the date by declaring a symbol to contain the programmer's choice of date formats. The #CASE structure assigns that choice to the %DateUsePicture symbol. The #IF(%DisplayTime) structure sets up to display the time by declaring a symbol to contain the programmer's choice of date formats. The #CASE structure assigns that choice to the %TimeUsePicture symbol. The #ENDAT statement terminates the #ATSTART section. The next #AT generates code into the embed point that appears immediately before the window data structure. The #IF(%DisplayDate AND %ShowDayOfWeek) structure generates two local variable declarations for the procedure if the programmer is displaying the date with the day of week. The next #AT generates code into the embed point that appears immediately before the ACCEPT loop. The #IF(%DisplayTime OR %DisplayDate) structure generates code that ensures the window has its TIMER attribute set. The IF NOT INRANGE(%Window{Prop:Timer},1,100) detects the lack of the attribute, then %Window{Prop:Timer} = 100 sets it to one second. The #INSERT(%DateTimeDisplayCode) adds the code that updates the display. The next #AT generates code into the embed point for EVENT:Timer. This embed point only appears if the programmer has placed a TIMER attribute on the window. Therefore, the #SET(%TimerEventGenerated,%True) statement signals that code was generated in this embed point. The #IF(%DisplayTime OR %DisplayDate) structure ensures the #INSERT(%DateTimeDisplayCode) statement generates the code that updates the display every time EVENT:Timer is processed. The next #AT generates code into the "Other Window Event Handling" embed point. This is the ELSE clause of the CASE EVENT() structure to handle field-independent events. #IF(NOT %TimerEventGenerated) detects that the previous #AT did not generate code because the programmer did not place the TIMER attribute on the window. Therefore, the IF EVENT() = EVENT:Timer structure is necessary for the code that updates the display whenever EVENT:Timer occurs. **See Also:     **[[ datetimedisplaycode group.htm|%DateTimeDisplayCode #GROUP]]