You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Create a reusable part (in this example it is called EOEXAM04). Copy and paste the code from the source code supplied below.
Set its Group property to Dates & Times then compile it.
The reusable part contains an input field in which a date can be entered and a label that will display the formatted date:

When the part is executed (in a form) it will look like this:

The part has three user-defined properties:

uCaption

Is used to the set the caption for the date field.

uDate

Is used to set and validate the entered and to retrieve it.

UInError

Is set to True if the date cannot be validated.

 
Source for Date Display Reusable Part
FUNCTION options(*DIRECT)
BEGIN_COM role(*EXTENDS #PRIM_PANL) DISPLAYPOSITION(1) HEIGHT(19) LEFT(0) TABPOSITION(1) TABSTOP(False) TOP(0) VISUALSTYLE(#VS_NORM) WIDTH(417)
DEFINE_COM class(#DATEC.Visual) name(#SHOWDATE) CAPTION('Date') DISPLAYPOSITION(1) HEIGHT(19) LABELTYPE(Caption) MARGINLEFT(120) PARENT(#COM_OWNER) TABPOSITION(1) WIDTH(177)
DEFINE_COM class(#PRIM_LABL) name(#SHOWTEXT) CAPTION('<text>') DISPLAYPOSITION(2) HEIGHT(19) LEFT(184) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(0) WIDTH(233)
DEFINE field(#RETCODE) type(*CHAR) length(1) desc('Return Code')
DEF_COND name(*OKAY) cond('#RetCode = Y')
DEFINE field(#CVTDATE) type(*CHAR) length(20)

  • Published Properties
    DEFINE_PTY name(uCaption) set(Set_uCaption)
    DEFINE_PTY name(uDate) get(Get_uDate) set(Set_uDate)
    DEFINE_PTY name(uInError) get(Get_uInError) set(Set_uInError)
  • Property Handling routine
    PTYROUTINE name(Set_uCaption)
    DEFINE_MAP for(*input) class(#Std_TextL) name(#Property_001)
    SET com(#ShowDate) CAPTION(#Property_001.Value)
    ENDROUTINE
    PTYROUTINE name(Set_uInError)
    DEFINE_MAP for(*input) class(#Std_Bool) name(#Property_002)
    SET com(#ShowDate) SHOWERROR(#Property_002.Value)
    ENDROUTINE
    PTYROUTINE name(Get_uInError)
    DEFINE_MAP for(*Output) class(#Std_Bool) name(#Property_002)
    SET com(#Property_002) VALUE(#ShowDate.ShowError)
    ENDROUTINE
    PTYROUTINE name(Set_uDate)
    DEFINE_MAP for(*input) class(#DateC) name(#Property_003)
    SET com(#ShowDate) VALUE(#Property_003.Value)
    INVOKE method(#Com_Self.ValidateDate)
    ENDROUTINE
    PTYROUTINE name(Get_uDate)
    DEFINE_MAP for(*Output) class(#DateC) name(#Property_003)
    SET com(#Property_003) VALUE(#ShowDate.Value)
    ENDROUTINE
  • Handle change of date by validating its value
    EVTROUTINE handling(#SHOWDATE.Changed) options(*NOCLEARMESSAGES *NOCLEARERRORS)
    INVOKE method(#Com_Self.ValidateDate)
    ENDROUTINE
  • Method to validate the date
    MTHROUTINE name(ValidateDate)
    SET com(#Com_Owner) UINERROR(FALSE)
    CHANGE field(#DATEC) to('#SHOWDATE.VALUE')
    IF_NULL field(#DATEC)
    SET com(#ShowText) CAPTION('No date specified')
    ELSE
    USE builtin(CONVERTDATE) with_args(#DATEC F Q) to_get(#CVTDATE #RETCODE)
    IF cond(*OKAY)
    SET com(#ShowText) CAPTION(#CvtDate)
    ELSE
    SET com(#Com_Owner) UINERROR(TRUE)
    SET com(#ShowText) CAPTION('Invalid Date')
    ENDIF
    ENDIF
    ENDROUTINE
    END_COM

  • No labels