guides:revdotnet:the_.net_calendar_control

The .NET Calendar Control

In the Form Designer, create a new form. Add the OLE control to the form, name it DOTNET, and set the CLSID property to Revelation4_10.Invoker. Select the DOTNET control, and in the “Events” for the control indicate that the OLE event should call your commuter module. Also add a button, named BUTTON_OK, and have its “click” event call your commuter module.

In the Stored Procedure Editor, create your commuter module. Be sure to add the following insert:

$INSERT REVDOTNETEQUATES

Declare a named common to hold the “handles” to the RevDotNet objects, some helper functions, and some equates to make our code easier to understand:

Declare Function CheckDotNet, Get_Property, Set_Property

COMMON /REVSHOW/ dotNetHandle, hndlCal

Equ FORMNAME To CTRLENTID[1,"."]

Equ DOTNETCTL To FORMNAME:'.DOTNET'

Equ BUTTON_OK To FORMNAME:’.BUTTON_OK’

On the “create” event of the form, initialize the RevDotNet interface:

Case EVENT _EQC "CREATE"

dotNetHandle = StartDotNet(DotNetCtl)

dotNetDir = CheckDotNet("4.0"):"\"

rslt = Set_Property.net(dotNetHandle, "AssemblyName", dotNetDir:"System.Windows.Forms.dll")

Note the use of the CheckDotNet utility routine; this function returns the directory where the .NET assemblies are stored (for the specified version of .NET).

Now that the path to the .NET assemblies has been set, we can create an instance of the calendar object:

ourClass = "System.Windows.Forms.MonthCalendar"

* Create the control

hndlCal = create_class.net(DotNetHandle, ourClass)

If Get_Status(errs) Then

                Gosub handleError

End

Note the use of the Get_Status function to determine if any errors occurred during the RevDotNet API call. Also note that no “Visible?” flag is passed; create_class.net will assume that .NET objects created using the RevDotNet OCX are visible, while those created using the “dynamic” object are not.

Once the object is created, you can determine additional details about it using the get_info.net API call, you can indicate which events you wish to handle in your commuter module, and you can start to manipulate the object with set_property.net, get_property.net, and send_message.net:

* Get some more info about this specific control

mthds = get_info.net(hndlCal, REVDOTNET_INFO_METHODS)

If Get_Status(errs) Then

                Gosub handleError

                End

mthd = get_info.net(hndlCal, REVDOTNET_INFO_METHODS, "AddBoldedDate")

If Get_Status(errs) Then

                Gosub handleError

End

props = get_info.net(hndlCal, REVDOTNET_INFO_PROPERTIES)

If Get_Status(errs) Then

                Gosub handleError

End

prop = get_info.net(hndlCal, REVDOTNET_INFO_PROPERTIES, "TitleForeColor")

If Get_Status(errs) Then

                Gosub handleError

End

events = get_info.net(hndlCal, REVDOTNET_INFO_EVENTS)

If Get_Status(errs) Then

                Gosub handleError

End

* Set up the events we care about

events.net(hndlCal, 'ForeColorChanged')

events.net(hndlCal, 'DateSelected')

* Show we can change a property

rslt = set_property.net(hndlCal, "TitleForeColor", "Red")

rslt = Set_property.net(hndlCal, "SelectionStart", "03/18/2018")

rslt = set_property.net(hndlCal, "SelectionEnd", "03/26/2018")

rslt = set_property.net(hndlCal, "ShowWeekNumbers", "True")

* And invoke a method

rslt = send_message.net(hndlCal, "AddBoldedDate", "2018-04-22", "System.DateTime")

rslt = send_message.net(hndlCal, "AddBoldedDate", "04/26/2018", "System.DateTime")

rslt = send_message.net(hndlCal, "UpdateBoldedDates")

Note how the get_info.net API can return information on all the properties, methods, events, etc., or on a specific property, method, event, etc.

When an event on the form has been triggered, your commuter module can handle it:

Case event _eqc "OLE" And P1 _eqc "DotNetEvent"

                caller = P2<1,1>

                event = P2<1,2>

                If EVENT _EQC "ONDATESELECTED" Then

                                 STDT = P2<1,4,1>

                                EDDT = P2<1,4,2>

                                If STDT = EDDT Then

                                                 OUTSTR = STDT

                                End Else

                                                   OUTSTR = STDT:'-':EDDT

                                End

                                Call Msg(@window, “You selected “: OUTSTR:@FM:”BOK”)

                End ELSE

                                Call Msg(@window, "Event ":event:" has happened!":@FM:"BOK")

                END

Note that different types of events will return different information; this information can be found in the passed parameter.

When the user clicks the OK button, capture the currently selected dates and close the form:

Case CtrlEntId _eqc BUTTON_OK

selStart = get_property.net(hndlCal, "SelectionStart")

selEnd = get_property.net(hndlCal, "SelectionEnd")

DATE1 = Iconv(Field(selStart," ",1), "D")

DATE2 = Iconv(Field(selEnd," ",1), "D")

OutDate = Oconv(DATE1,'D4/')

If DATE1 <> DATE2 Then

                OutDate := " - ":Oconv(Date2,'D4/')

END

Call Msg(@WINDOW, "Selected date(s): ":OutDate:@FM:"BOK")

Call Send_event(FormName, "CLOSE")

The full text of the commuter module is then:

REVDOTNET_EXAMPLE_COMMUTER_MODULE
Function REVDOTNET_EXAMPLE_COMMUTER_MODULE(ctrlentid,event,p1,p2,p3,p4,p5,p6)

*

$Insert REVDOTNETEQUATES

*

Declare Function CheckDotNet, Get_Property, Set_Property

*

COMMON /REVSHOW/ dotNetHandle, hndlCal

*

Equ FORMNAME To CTRLENTID[1,"."]

Equ DOTNETCTL To FORMNAME:'.DOTNET'

Equ BUTTON_OK To FORMNAME:'.BUTTON_OK'

Equ BUTTON_COLOR To FORMNAME:'.BUTTON_COLOR'

*

ERRS = ""

RSLT = 0

 

Begin Case

               

                Case EVENT _EQC "CREATE"

 

                                dotNetHandle = StartDotNet(DotNetCtl)

                                dotNetDir = CheckDotNet("4.0"):"\"

                                rslt = Set_Property.net(dotNetHandle, "AssemblyName", dotNetDir:"System.Windows.Forms.dll")

                               

                                ourClass = "System.Windows.Forms.MonthCalendar"

                                * Determine some info about the assembly and its classes

                                classes = get_info.net(DotNetHandle, REVDOTNET_INFO_CLASSES)

                                If Get_Status(ERRS) Then

                                                Gosub handleError

                                End

                               

                                * Create the control

                                hndlCal = create_class.net(DotNetHandle, ourClass)

                                If Get_Status(errs) Then

                                                Gosub handleError

                                End

 

                                * Get some more info about this specific control

                                mthds = get_info.net(hndlCal, REVDOTNET_INFO_METHODS)

                                If Get_Status(errs) Then

                                                Gosub handleError

                                End

                                mthd = get_info.net(hndlCal, REVDOTNET_INFO_METHODS, "AddBoldedDate")

                                If Get_Status(errs) Then

                                                Gosub handleError

                                End

 

                                props = get_info.net(hndlCal, REVDOTNET_INFO_PROPERTIES)

                                If Get_Status(errs) Then

                                                Gosub handleError

                                End

 

                                prop = get_info.net(hndlCal, REVDOTNET_INFO_PROPERTIES, "TitleForeColor")

                                If Get_Status(errs) Then

                                                Gosub handleError

                                End

                               

                                events = get_info.net(hndlCal, REVDOTNET_INFO_EVENTS)

                                If Get_Status(errs) Then

                                                Gosub handleError

                                End

 

                                * Set up the events we care about

                                events.net(hndlCal, 'ForeColorChanged')

                                events.net(hndlCal, 'DateSelected')

                               

                                * Show we can change a property

                                rslt = set_property.net(hndlCal, "TitleForeColor", "Red")

                                rslt = Set_property.net(hndlCal, "SelectionStart", "03/18/2018")

                                rslt = set_property.net(hndlCal, "SelectionEnd", "03/26/2018")

                                rslt = set_property.net(hndlCal, "ShowWeekNumbers", "True")

                               

                                * And invoke a method

                                rslt = send_message.net(hndlCal, "AddBoldedDate", "2018-04-22", "System.DateTime")

                                rslt = send_message.net(hndlCal, "AddBoldedDate", "04/26/2018", "System.DateTime")

                                rslt = send_message.net(hndlCal, "UpdateBoldedDates")

                               

                                * resize the control

                                Gosub resizeMe

                               

                Case event _eqc "Size"

                                Gosub resizeMe

               

                Case event _eqc "OLE" And P1 _eqc "DotNetEvent"

                                caller = P2<1,1>

                                event = P2<1,2>

                                Call Msg(@window, "Event ":event:" has happened!":@FM:"BOK")

               

                Case EVENT _EQC "CLICK"

                                Begin Case

                                                Case CtrlEntId _eqc BUTTON_COLOR

                                                                colorList = "Red,Blue,Green,Black"

                                                                currColor = get_property.net(hndlCal, "ForeColor")

                                                                * Returned as "Color [<value>]" - just extract the color name

                                                                currColor = Field(currColor, "[", 2)

                                                                currColor[-1,1] = ""

                                                                Locate currColor In colorList Using "," Setting currLoc Else currLoc = 0

                                                                currLoc += 1

                                                                If currLoc > 4 Then currLoc = 1

                                                                newColor = Field(colorList, ",", currLoc)

                                                                rslt = set_property.net(hndlCal, "ForeColor", newColor)

                                                Case CtrlEntId _eqc BUTTON_OK

                                                                selStart = get_property.net(hndlCal, "SelectionStart")

                                                                selEnd = get_property.net(hndlCal, "SelectionEnd")

                                                                DATE1 = Iconv(Field(selStart," ",1), "D")

                                                                DATE2 = Iconv(Field(selEnd," ",1), "D")

                                                                OutDate = Oconv(DATE1,'D4/')

                                                                If DATE1 <> DATE2 Then

                                                                                OutDate := " - ":Oconv(Date2,'D4/')

                                                                END

                                                                Call Msg(@WINDOW, "Selected date(s): ":OutDate:@FM:"BOK")

                                                                Call Send_event(FormName, "CLOSE")

                                End Case

               

End Case

 

Return RSLT

 

 

HandleError:

Convert @FM To @VM In ERRS

Call Msg(@WINDOW, "ERROR: ":ERRS:@FM:"BOK")

Return

 

ResizeMe:

csize = Get_Property(DotNetCtl, "SIZE")

width = csize<3> - 20

height = csize<4> - 20

rslt = set_property.net(hndlCal, "Height", height)

rslt = set_property.net(hndlCal, "Width", width)

return

The form and commuter module are available for your reference; please look at the REVDOTNET_EXAMPLES form and the REVDOTNET_EXAMPLE_COMMUTER_MODULE source in the EXAMPLE application for further information.

  • guides/revdotnet/the_.net_calendar_control.txt
  • Last modified: 2023/10/25 10:49
  • by 127.0.0.1