Table of Contents
Examples
The examples in this section are designed to provide an overview of the use of CalendarSet and the basic commands. The examples are included on your CalendarSet disk, to allow experimentation with the commands and parameters.
These examples use CalendarSet commands to configure the behavior of an object, rather than the Advanced Properties Dialog. You can reduce the programming effort by using the Advanced Properties Dialog. Please read the section Using the Advanced Properties Dialog for more information.
Note: all the examples below, and many others, are available in the CalendarSet Demonstration database.
Example 1 — Create a Simple Calendar
For this example, we will create a simple form containing a single CalendarSet object. When the user clicks on a day, we will put the selected date into a variable called vSelDate.
First we need to create the form and draw the CalendarSet plugin object. We’ll name the object eCalendar.
Our form now looks something like this:
The object method for the CalendarSet object is:
If(Form event=On Clicked) CS_GetAction (Self->;vAction) If(vAction=CS_Action_ClickOnDay) // clicked on a day CS_GetSelect(Self->;vSelDate;vSelDateE;isContig;aDates) End if End if
The form will appear like this in the User or Runtime environment:
Notice that we’ve used the default configuration options, and the only programming required is a couple of commands to detect a click on a day, then determine what day the user has selected.
Example 2 — Display Database Data in a Calendar
Modify the previous example to display information from the [Cal Items] file on the calendar. The file structure for this example is:
The On Load section of the modified object method for the CalendarSet object is:
Case of : (Form event=On Load) vSelDate:=!00/00/00! CS_SetRange(Self->;!02/01/2015!;!02/28/2015!) QUERY([Cal Items];[Cal Items]ItemType=1) // Items of type 1 are text items for this demo SELECTION TO ARRAY([Cal Items]StartDate;vTextDate;[Cal Items]Description;vTextDesc;\ [Cal Items]Font;vTextFont;[Cal Items]Size;vTextSize;[Cal Items]Style;vTextStyle;\ [Cal Items]ForeColor;vTextColor) CS_SetArray(Self->;"vTextDate";"vTextDesc";"vTextFont";"vTextSize";"vTextStyle";"vTextColor") (...) End case
The CalendarSet object now appears in the User or Runtime environment like this:
Example 3 — Displaying Banners on a Calendar
We’ll change the previous example to also display banner items. We can use the same CalendarSet object we created in the previous examples, and just modify the object method.
CS_SetEventOpts is not used, therefore event selection is disabled (default).
Conversely, CS_SetBanrOpts is not used either but this function defaults its parameters to 1 in this case (AllowBannerSelect, AllowBannerResize): banners are selectable and resizable.
Our new object method is:
Case of : (Form event=On Load) vSelDate:=!00/00/00! // set the range of the calendar to be Feb 2015 CS_SetRange(Self->;!02/01/2015!;!02/28/2015!) // Items of type 1 are text items // Find all of the text items QUERY([Cal Items];[Cal Items]ItemType=1) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vTextDate;[Cal Items]Description;vTextDesc;\ [Cal Items]Font;vTextFont;[Cal Items]Size;vTextSize;[Cal Items]Style;vTextStyle;\ [Cal Items]ForeColor;vTextColor) // pass the arrays to CalendarSet CS_SetArray(Self->;"vTextDate";"vTextDesc";"vTextFont";"vTextSize";"vTextStyle";"vTextColor") // Items of type 2 are Banner items // Find all of the Banner items QUERY([Cal Items];[Cal Items]ItemType=2) // pass the arrays to CalendarSet SELECTION TO ARRAY([Cal Items]StartDate;vBanrDateS;[Cal Items]EndDate;vBanrDateE;\ [Cal Items]Description;vBanrDesc;[Cal Items]Font;vBanrFont;[Cal Items]Size;vBanrSize;\ [Cal Items]Style;vBanrStyle;[Cal Items]ForeColor;vBanrColorF;[Cal Items]BackColor;vBanrColorB) // pass the arrays to CalendarSet CS_SetBanrArray(Self->;"vBanrDateS";"vBanrDateE";"vBanrDesc";"vBanrFont";\ "vBanrSize";"vBanrStyle";"vBanrColorF";"vBanrColorB") :(Form event=On Clicked) CS_GetAction (Self->;vAction) Case of :(vAction=CS_Action_ClickOnDay) // clicked on a day CS_GetSelect(Self->;vSelDate;vSelDateE;isContig;aDates) :(vAction=CS_Action_ClickOnEventBanner)|(vAction=CS_Action_BannerResize) // clicked on a banner (including resize) - events default to non selectable so this is a banner CS_GetEvtSelect (Self->;vEvtType;vIndex) vSelDate:= vBanrDateS{vIndex} // start date of this banner End case End case
Our form now looks like this to the user:
Example 4 — Responding to User Actions
In the previous examples, we’ve gradually added capabilities to the calendar object, so that we can display both text and banner items, and identify the day clicked by a user.
For this example, we’ll implement a vSelected text variable which shows information about the day or days selected.
Here’s the modified object method:
Case of : (Form event=On Load) vSelDate:=!00/00/0000! vSelDateE:=!00/00/0000! vSelected:="Select one or several day(s) or a banner..." ARRAY LONGINT(vSelItems;0) // index of selected items ARRAY TEXT(vSelText;0) // selected items text // set the range of the calendar to be Feb 2015 CS_SetRange(Self->;!02/01/15!;!02/28/15!) // Items of type 1 are text items // Find all of the text items QUERY([Cal Items];[Cal Items]ItemType=1) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vTextDate;[Cal Items]Description;vTextDesc;\ [Cal Items]Font;vTextFont;[Cal Items]Size;vTextSize;[Cal Items]Style;vTextStyle;\ [Cal Items]ForeColor;vTextColor) // pass the arrays to CalendarSet CS_SetArray (Self->;"vTextDate";"vTextDesc";"vTextFont";"vTextSize";"vTextStyle";"vTextColor") // Items of type 2 are Banner items // Find all of the Banner items QUERY([Cal Items];[Cal Items]ItemType=2) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vBanrDateS;[Cal Items]EndDate;vBanrDateE;\ [Cal Items]Description;vBanrDesc;[Cal Items]Font;vBanrFont;[Cal Items]Size;vBanrSize;\ [Cal Items] Style;vBanrStyle;[Cal Items]ForeColor;vBanrColorF;[Cal Items]BackColor;vBanrColorB) // pass the arrays to CalendarSet CS_SetBanrArray(Self->;"vBanrDateS";"vBanrDateE";\ "vBanrDesc";"vBanrFont";"vBanrSize";"vBanrStyle";"vBanrColorF";"vBanrColorB") // Set the options to display entire highlight, allow discontiguous selection, // do not show day number for unused days, display month names and OS first day of the week CS_Options (Self->;CS_Highlight_Cell;CS_DaySelect_Discontiguous;\ CS_Unused_GrayedEmpty;CS_MonthOnFirstOn;CS_FirstDayOS) : (Form event=On Clicked) CS_GetAction (Self->;vAction) Case of :(vAction=CS_Action_ClickOnDay) // clicked on a day CS_GetSelect(Self->;vSelDate;vSelDateE;isContig;aDates) // get an index of the selected items CS_GetSelItems (Self->;CS_Sel_Events;vSelItems) // create an array of the selected items only, using the index FS_ArrayIntrsct (vSelItems;vTextDesc;vSelText) vSelected:=ArrayToText (->vSelText;", ") :(vAction=CS_Action_ClickOnEventBanner)|(vAction=CS_Action_BannerResize) // clicked on a banner (including resize) - events default to non selectable so this is a banner CS_GetEvtSelect (Self->;vEvtType;vIndex) vSelected:="Banner: "+vBanrDesc{vIndex} // text associated to this banner End case End case
The 4D ArrayToText project method simply concatenates text array items into a text variable:
C_POINTER($1) //->array C_TEXT($2) //separator C_TEXT($0) //text C_LONGINT($i) $0:="" For ($i;1;Size of array($1->)) $0:=$0+$1->{$i}+$2 End for $0:=Substring($0;1;Length($0)-Length($2)) // remove last separator
Here is the resulting form:
Example 5 — Dragging Events within a CalendarSet Object
Once again we’ll modify the example, to allow events and banners to be dragged within the CalendarSet area.
Since CalendarSet will automatically update the date arrays for events when they are dragged within an object, we don’t have to handle the user actions (although we could do this if needed).
We use CS_SetDrgSrc and CS_SetDrgDst to restrict event dragging to be within the object.
Here’s the modified object method:
Case of : (Form event=On Load) vSelected:="Drag events or banners..." // set the range of the calendar to be Feb 2015 CS_SetRange(Self->;!02/01/15!;!02/28/15!) // Items of type 1 are text items // Find all of the text items QUERY([Cal Items];[Cal Items]ItemType=1) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vTextDate;[Cal Items]Description;vTextDesc;\ [Cal Items]Font;vTextFont;[Cal Items]Size;vTextSize;[Cal Items]Style;\ vTextStyle;[Cal Items]ForeColor;vTextColor) // pass the arrays to CalendarSet CS_SetArray (Self->;"vTextDate";"vTextDesc";"vTextFont";"vTextSize";"vTextStyle";"vTextColor") // Items of type 2 are Banner items // Find all of the Banner items QUERY([Cal Items];[Cal Items]ItemType=2) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vBanrDateS;[Cal Items]EndDate;vBanrDateE;\ [Cal Items]Description;vBanrDesc;[Cal Items]Font;vBanrFont;[Cal Items]Size;vBanrSize;\ [Cal Items]Style;vBanrStyle;[Cal Items]Forecolor;vBanrColorF;[Cal Items]Backcolor;vBanrColorB) // pass the arrays to CalendarSet CS_SetBanrArray (Self->;"vBanrDateS";"vBanrDateE";"vBanrDesc"; \ "vBanrFont";"vBanrSize";"vBanrStyle";"vBanrColorF";"vBanrColorB") // Set the options to display entire highlight, allow discontiguous selection, // do not show day number for unused days, display month names and OS first day of the week CS_Options (Self->;CS_Highlight_Cell;CS_DaySelect_Discontiguous;\ CS_Unused_GrayedEmpty;CS_MonthOnFirstOn;CS_FirstDayOS) // enable dragging banners and events to days within this area vAccessCode:="CalendarSetArea"+String(Self->) // allows dragging within this area //make events selectable to enable dragging (see the note to CS_SetDrgSrc) CS_SetEventOpts(Self->;CS_EventSelect_Single) CS_SetDrgSrc (Self->;CS_DragSource_EventBanner;vAccessCode) // source: event or banner CS_SetDrgDst (Self->;CS_DragDestination_Day;vAccessCode) // destination: day : (Form event=On Drop) // could also be CS_Action_Drop from CS_GetAction C_LONGINT($SourceArea;$SourceProcessID) C_DATE($StartDate) CS_GetDrgSrcArea (Self->;$SourceArea;$SourceProcessID) // or DRAG AND DROP PROPERTIES If ($SourceArea=Self->) // drag within CS_GetDrgSrcEvt (Self->;vDataType;vEventIndex;$StartDate) // what was dragged CS_GetDrgDstDay (Self->;$DestDate) // to which day Case of : ($DestDate=!00/00/0000!) // invalid date ("unused day") : (vDataType=CS_Type_Event) // only one event can be selected at a time (CS_EventSelect_Single) vSelected:="Event dropped from "+String($StartDate)+" to "+String($DestDate)+": "\ +vTextDesc{vEventIndex} : (vDataType=CS_Type_Banner) // only one banner can be selected at a time vSelected:="Banner dropped from "+String($StartDate)+" to "+String($DestDate)+": "\ +vBanrDesc{vEventIndex} End case End if End case
Here is the resulting form:
Example 6 — Dragging Events to another CalendarSet Object on the Same Form
Our previous example only allowed events and banners to be dragged within the CalendarSet area.
Since CalendarSet automatically updates the date arrays for events when they are dragged within an object, we didn’t have to handle the user actions. We’ll extend our example to show how to handle drags between CalendarSet objects on the same form. The two objects are named eCalendar and eOther.
Instead of displaying a message as in the previous example, we will update both calendars once a drop has occurred. When the user drags and drop an event from eCalendar to eOther, we’ll remove that event from eCalendar and “paste” it into the arrays displayed in eOther.
We’ll show both the object method for eCalendar (loading and displaying data) and the destination area eOther (setting an empty calendar on load, then updating both areas after a drop).
// eCalendar (source area) object method Case of : (Form event=On Load) // set the range of the calendar to be Feb 2015 CS_SetRange(Self->;!02/01/15!;!02/28/15!) // Items of type 1 are text items // Find all of the text items QUERY([Cal Items];[Cal Items]ItemType=1) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vTextDate;[Cal Items]Description;vTextDesc;\ [Cal Items]Font;vTextFont;[Cal Items]Size;vTextSize;[Cal Items]Style;\ vTextStyle;[Cal Items]ForeColor;vTextColor) // pass the arrays to CalendarSet CS_SetArray (Self->;"vTextDate";"vTextDesc";"vTextFont";"vTextSize";"vTextStyle";"vTextColor") // Items of type 2 are Banner items // Find all of the Banner items QUERY([Cal Items];[Cal Items]ItemType=2) // load the arrays with the data SELECTION TO ARRAY([Cal Items]StartDate;vBanrDateS;[Cal Items]EndDate;vBanrDateE;\ [Cal Items]Description;vBanrDesc;[Cal Items]Font;vBanrFont;[Cal Items]Size;vBanrSize;\ [Cal Items]Style;vBanrStyle;[Cal Items]Forecolor;vBanrColorF;[Cal Items]Backcolor;vBanrColorB) // pass the arrays to CalendarSet CS_SetBanrArray (Self->;"vBanrDateS";"vBanrDateE";"vBanrDesc"; \ "vBanrFont";"vBanrSize";"vBanrStyle";"vBanrColorF";"vBanrColorB") // Set the options to display entire highlight, allow discontiguous selection, // do not show day number for unused days, display month names and OS first day of the week CS_Options (Self->;CS_Highlight_Cell;CS_DaySelect_Discontiguous;\ CS_Unused_GrayedEmpty;CS_MonthOnFirstOn;CS_FirstDayOS) // enable dragging events and banners from this area to days in eOther vAccessCode:="CalendarSetArea"+String(Self->)+"to"+String(eOther) // allows dragging between CS_SetEventOpts(Self->;CS_EventSelect_Single) //make events selectable to enable dragging CS_SetDrgSrc (Self->;CS_DragSource_EventBanner;vAccessCode) // source: event or banner CS_SetDrgDst (eOther;CS_DragDestination_Day;vAccessCode) // destination: day in eOther End case
// eOther (destination area) object method Case of : (Form event=On Load) // set the range of the calendar to be Feb 2015 CS_SetRange(Self->;!02/01/15!;!02/28/15!) // Empty arrays for events and banners ARRAY DATE(vTextDateDes;0) ARRAY TEXT(vTextDescDes;0) ARRAY TEXT(vTextFontDes;0) ARRAY INTEGER(vTextSizeDes;0) ARRAY INTEGER(vTextStyleDes;0) ARRAY INTEGER(vTextColorDes;0) CS_SetArray (Self->;"vTextDateDes";"vTextDescDes";"vTextFontDes";\ "vTextSizeDes";"vTextStyleDes";"vTextColorDes") ARRAY DATE(vBanrDateSDes;0) ARRAY DATE(vBanrDateEDes;0) ARRAY TEXT(vBanrDescDes;0) ARRAY TEXT(vBanrFontDes;0) ARRAY INTEGER(vBanrSizeDes;0) ARRAY INTEGER(vBanrStyleDes;0) ARRAY INTEGER(vBanrColorFDes;0) ARRAY INTEGER(vBanrColorBDes;0) // Set the options to display entire highlight, allow discontiguous selection, // do not show day number for unused days, display month names and OS first day of the week CS_SetBanrArray (Self->;"vBanrDateSDes";"vBanrDateEDes";"vBanrDescDes";\ "vBanrFontDes";"vBanrSizeDes";"vBanrStyleDes";"vBanrColorFDes";"vBanrColorBDes") : (Form event=On Drop) // could also be CS_Action_Drop from CS_GetAction C_LONGINT($SourceArea;$SourceProcessID) C_DATE($StartDate) CS_GetDrgSrcArea (Self->;$SourceArea;$SourceProcessID) // or DRAG AND DROP PROPERTIES If ($SourceArea=eCalendar) // drag from eCalendar CS_GetDrgSrcEvt (Self->;vDataType;vEventIndex;$StartDate) // what was dragged CS_GetDrgDstDay (Self->;$DestDate) // to which day Case of // we check that the destination date is within the range set with CS_SetRange : ($DestDate=!00/00/0000!) // invalid date ("unused day") : (vDataType=CS_Type_Event) // only one event can be selected at a time (CS_EventSelect_Single) //Add to destination APPEND TO ARRAY(vTextDateDes;$DestDate) APPEND TO ARRAY(vTextDescDes;vTextDesc{vEventIndex}) APPEND TO ARRAY(vTextFontDes;vTextFont{vEventIndex}) APPEND TO ARRAY(vTextSizeDes;vTextSize{vEventIndex}) APPEND TO ARRAY(vTextStyleDes;vTextStyle{vEventIndex}) APPEND TO ARRAY(vTextColorDes;vTextColor{vEventIndex}) // Remove from source DELETE FROM ARRAY(vTextDate;vEventIndex) DELETE FROM ARRAY(vTextDesc;vEventIndex) DELETE FROM ARRAY(vTextFont;vEventIndex) DELETE FROM ARRAY(vTextSize;vEventIndex) DELETE FROM ARRAY(vTextStyle;vEventIndex) DELETE FROM ARRAY(vTextColor;vEventIndex) : (vDataType=CS_Type_Banner) // only one banner can be selected at a time (default) //Add to destination APPEND TO ARRAY(vBanrDateSDes;$DestDate) APPEND TO ARRAY(vBanrDateEDes;$DestDate+\ (vBanrDateE{vEventIndex}-vBanrDateS{vEventIndex})) //sameduration APPEND TO ARRAY(vBanrDescDes;vBanrDesc{vEventIndex}) APPEND TO ARRAY(vBanrFontDes;vBanrFont{vEventIndex}) APPEND TO ARRAY(vBanrSizeDes;vBanrSize{vEventIndex}) APPEND TO ARRAY(vBanrStyleDes;vBanrStyle{vEventIndex}) APPEND TO ARRAY(vBanrColorFDes;vBanrColorF{vEventIndex}) APPEND TO ARRAY(vBanrColorBDes;vBanrColorB{vEventIndex}) // Remove from source DELETE FROM ARRAY(vBanrDateS;vEventIndex) DELETE FROM ARRAY(vBanrDateE;vEventIndex) DELETE FROM ARRAY(vBanrDesc;vEventIndex) DELETE FROM ARRAY(vBanrFont;vEventIndex) DELETE FROM ARRAY(vBanrSize;vEventIndex) DELETE FROM ARRAY(vBanrStyle;vEventIndex) DELETE FROM ARRAY(vBanrColorF;vEventIndex) DELETE FROM ARRAY(vBanrColorB;vEventIndex) End case Area_Refresh (eCalendar) Area_Refresh (Self->) End if End case
Here is the resulting form, after dropping a banner and an event:
Example 7 — Dragging Events to a CalendarSet Object on a Different Form
We’ll modify the previous example to show how to handle dragging events to a CalendarSet object on a different form. Instead of the eOther object being on the same form, we’ll put it on a different form (in another process).
We have to use the 4D process communication commands to assist with the implementation. When we detect a drop from eCalendar to eOther, our eOther object method will update the arrays.
// eCalendar (source area) object method Case of : (Form event=On Load) // we’ll not show the standard setup stuff, and just show the dragging-specific code (…) // store both process numbers in interprocess variables for process communication <>DragDemo:=Current process // display the other form in its own process <>DragDemo2:=New process("Example";0;"Other process";"7 Other") // enable dragging events and banners from this area to days in eOther vAccessCode:="CalendarSetArea"+String(<>DragDemo)+"to"+String(<>DragDemo2) CS_SetEventOpts (Self->;CS_EventSelect_Single) // make events selectable to enable dragging CS_SetDrgSrc (Self->;CS_DragSource_EventBanner;vAccessCode) // source: event or banner // destination is set in the other process (eOther object method) End case
// eOther object method Case of : (Form event=On Load) // we’ll not show the standard setup stuff, and just show the dragging-specific code (...) vAccessCode:="CalendarSetArea"+String(<>DragDemo)+"to"+String(<>DragDemo2) CS_SetDrgDst(eOther;CS_DragDestination_Day;vAccessCode) //destination:day : (Form event=On Drop) // could also be CS_Action_Drop from CS_GetAction C_LONGINT($SourceArea;$SourceProcessID) C_DATE($StartDate) CS_GetDrgSrcArea (Self->;$SourceArea;$SourceProcessID) // or DRAG AND DROP PROPERTIES If ($SourceProcessID=<>DragDemo) // drag from eCalendar in the source process CS_GetDrgSrcEvt (Self->;vDataType;vEventIndex;$StartDate) // what was dragged CS_GetDrgDstDay (Self->;$DestDate) // to which day If ($DestDate#!00/00/0000!) // valid date (not "unused day") C_LONGINT($Size) // new array size Case of : (vDataType=CS_Type_Event) // only one event can be selected at a time (CS_EventSelect_Single) //Add to destination APPEND TO ARRAY(vTextDateDes;$DestDate) $Size:=Size of array(vTextDateDes) INSERT IN ARRAY(vTextDescDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextDesc{vEventIndex};vTextDescDes{$Size}) INSERT IN ARRAY(vTextFontDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextFont{vEventIndex};vTextFontDes{$Size}) INSERT IN ARRAY(vTextSizeDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextSize{vEventIndex};vTextSizeDes{$Size}) INSERT IN ARRAY(vTextStyleDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextStyle{vEventIndex};vTextStyleDes{$Size}) INSERT IN ARRAY(vTextColorDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextColor{vEventIndex};vTextColorDes{$Size}) : (vDataType=CS_Type_Banner) // only one banner can be selected at a time (default) //Add to destination $Size:=Size of array(vBanrDateEDes)+1 INSERT IN ARRAY(vBanrDateSDes;$Size;1) // temporary report (source start date) GET PROCESS VARIABLE(<>DragDemo;vBanrDateS{vEventIndex};vBanrDateSDes{$Size}) INSERT IN ARRAY(vBanrDateEDes;$Size;1) // temporary report (source end date) GET PROCESS VARIABLE(<>DragDemo;vBanrDateE{vEventIndex};vBanrDateEDes{$Size}) // Real dates according to the original duration vBanrDateEDes{$Size}:=$DestDate+(vBanrDateEDes{$Size}- vBanrDateSDes{$Size}) vBanrDateSDes{$Size}:=$DestDate INSERT IN ARRAY(vBanrDescDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vBanrDesc{vEventIndex};vBanrDescDes{$Size}) INSERT IN ARRAY(vBanrFontDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vBanrFont{vEventIndex};vBanrFontDes{$Size}) INSERT IN ARRAY(vBanrSizeDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vBanrSize{vEventIndex};vBanrSizeDes{$Size}) INSERT IN ARRAY(vBanrStyleDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vBanrStyle{vEventIndex};vBanrStyleDes{$Size}) INSERT IN ARRAY(vBanrColorFDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vBanrColorF{vEventIndex};vBanrColorFDes{$Size}) INSERT IN ARRAY(vBanrColorBDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vBanrColorB{vEventIndex};vBanrColorBDes{$Size}) End case // Inform source: item to remove (index, type) VARIABLE TO VARIABLE(<>DragDemo;vEventIndex;vEventIndex;vDataType;vDataType) CALL PROCESS(<>DragDemo) Area_Refresh (Self->) End if // valid date End if //$SourceProcessID=<>DragDemo End case
// Destination form method (On Outside Call event) // eOther is calling: remove dragged item Case of // playing safe : (vEventIndex<1) : (vEventIndex>Size of array(vTextDate)) : (vDataType=CS_Type_Event) DELETE FROM ARRAY(vTextDate;vEventIndex) DELETE FROM ARRAY(vTextDesc;vEventIndex) DELETE FROM ARRAY(vTextFont;vEventIndex) DELETE FROM ARRAY(vTextSize;vEventIndex) DELETE FROM ARRAY(vTextStyle;vEventIndex) DELETE FROM ARRAY(vTextColor;vEventIndex) : (vDataType=CS_Type_Banner) DELETE FROM ARRAY(vBanrDateS;vEventIndex) DELETE FROM ARRAY(vBanrDateE;vEventIndex) DELETE FROM ARRAY(vBanrDesc;vEventIndex) DELETE FROM ARRAY(vBanrFont;vEventIndex) DELETE FROM ARRAY(vBanrSize;vEventIndex) DELETE FROM ARRAY(vBanrStyle;vEventIndex) DELETE FROM ARRAY(vBanrColorF;vEventIndex) DELETE FROM ARRAY(vBanrColorB;vEventIndex) End case Area_Refresh (eCalendar)
Here are the resulting forms, after dropping a banner and an event:
Example 8 — Dragging from AreaList Pro to CalendarSet
This is an example of dragging a row from an AreaList Pro list row in one process to a CalendarSet object in another process to create an event.
In this example we will also display event times.
We use the vEventIndex variable as a communication “token” between the two processes:
- When a drop is received, destination (CalendarSet) process sends vEventIndex=-1 to source (AreaList Pro) process, meaning “send me the index number of the row that was dragged”.
- Source process assigns the index value to vEventIndex for destination process to read.
- Destination process updates the CalendarSet area, then sends vEventIndex=-2 to source process, meaning “delete the selected row”.
This is one of many tricks that can be used for this kind of process communication.
First, the object method of the AreaList Pro (source) area (On Load event):
// load events QUERY([Cal Items];[Cal Items]ItemType=1) SELECTION TO ARRAY([Cal Items]Description;vTextDesc;[Cal Items]Time;vTextTime;\ [Cal Items]Font;vTextFont; [Cal Items]Size;vTextSize;[Cal Items]Style;vTextStyle;\ [Cal Items]ForeColor;vTextColor) // column setup (array mode) C_LONGINT($error) $error:=AL_AddColumn (Self->;->vTextDesc) $error:=AL_AddColumn (Self->;->vTextTime) $error:=AL_AddColumn (Self->;->vTextFont) $error:=AL_AddColumn (Self->;->vTextSize) $error:=AL_AddColumn (Self->;->vTextStyle) $error:=AL_AddColumn (Self->;->vTextColor) // column headers AL_SetColumnTextProperty (Self->;1;ALP_Column_HeaderText;"Description") AL_SetColumnTextProperty (Self->;2;ALP_Column_HeaderText;"Time") AL_SetColumnTextProperty (Self->;3;ALP_Column_HeaderText;"Font") AL_SetColumnTextProperty (Self->;4;ALP_Column_HeaderText;"Size") AL_SetColumnTextProperty (Self->;5;ALP_Column_HeaderText;"Style") AL_SetColumnTextProperty (Self->;6;ALP_Column_HeaderText;"Color") // formatting AL_SetColumnTextProperty (Self->;2;ALP_Column_Format;"&/105") AL_SetColumnTextProperty (Self->;4;ALP_Column_Format;"##0") AL_SetColumnTextProperty (Self->;5;ALP_Column_Format;"##0") AL_SetColumnTextProperty (Self->;6;ALP_Column_Format;"##0") // make it nicer AL_SetAreaLongProperty (Self->;ALP_Area_AutoResizeColumn;1) // autoresize columns 1 AL_SetAreaLongProperty (Self->;ALP_Area_AltRowOptions;1) // alternate row color AL_SetAreaLongProperty (Self->;ALP_Area_RowIndentH;10) // row indent (horizontal padding) // store both process numbers in interprocess variables for process communication <>DragDemo:=Current process // display the other form in its own process <>DragDemo2:=New process("Example";0;"Other process";"8 Other") // enable dragging rows from this AreaList Pro area to days in eOther CalendarSet area vAccessCode:="AreaListProArea"+String(<>DragDemo)+"to"+String(<>DragDemo2) AL_SetAreaTextProperty (Self->;ALP_Area_DragSrcRowCodes;vAccessCode) // area has been made draggable // destination (CalendarSet area) is set in the other process (eOther object method)
Next, the object method of the CalendarSet object in the destination form:
Case of : (Form event=On Load) GET PROCESS VARIABLE(<>DragDemo;eALP;eALP) // source area reference // set the range of the calendar to be Feb 2015 CS_SetRange(Self->;!02/01/15!;!02/28/15!) // Empty arrays for events ARRAY DATE(vTextDateDes;0) ARRAY LONGINT(vTextTimeDes;0) ARRAY TEXT(vTextDescDes;0) ARRAY TEXT(vTextFontDes;0) ARRAY INTEGER(vTextSizeDes;0) ARRAY INTEGER(vTextStyleDes;0) ARRAY INTEGER(vTextColorDes;0) CS_SetArray (Self->;"vTextDateDes";"vTextDescDes";"vTextFontDes";\ "vTextSizeDes";"vTextStyleDes";"vTextColorDes";"vTextTimeDes") // show times CS_SetEventOpts(Self->CS_EventSelect_Single;CS_WordWrap_Off;CS_Marker_None;CS_EventTime_Show) // Set the options to display entire highlight, allow discontiguous selection, // do not show day number for unused days, display month names and OS first day of the week CS_Options (Self->;CS_Highlight_Cell;CS_DaySelect_Discontiguous;\ CS_Unused_GrayedEmpty;CS_MonthOnFirstOn;CS_FirstDayOS) // enable dragging events to days in this area from the source AreaList Pro area vAccessCode:="AreaListProArea"+String(<>DragDemo->)+"to"+String(<>DragDemo2) CS_SetDrgDst (Self->;CS_DragDestination_Day;vAccessCode) // destination: day : (Form event=On Drop) // could also be CS_Action_Drop from CS_GetAction C_LONGINT($SourceArea;$SourceProcessID) C_DATE($StartDate) CS_GetDrgSrcArea (Self->;$SourceArea;$SourceProcessID) // or DRAG AND DROP PROPERTIES If ($SourceArea=-eALP) // drag from eALP in the source process (value is negative) CS_GetDrgDstDay (Self->;$DestDate) // to which day If ($DestDate#!00/00/0000!) // valid date (not "unused day") // Get information from source vEventIndex:=-1 // ask eALP process for selected row VARIABLE TO VARIABLE(<>DragDemo;vEventIndex;vEventIndex) CALL PROCESS(<>DragDemo) While (vEventIndex=-1) // wait for returned value GET PROCESS VARIABLE(<>DragDemo;vEventIndex;vEventIndex) // index of selected row End while C_LONGINT($Size) // new array size APPEND TO ARRAY(vTextDateDes;$DestDate) $Size:=Size of array(vTextDateDes) INSERT IN ARRAY(vTextDescDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextDesc{vEventIndex};vTextDescDes{$Size}) INSERT IN ARRAY(vTextTimeDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextTime{vEventIndex};vTextTimeDes{$Size}) INSERT IN ARRAY(vTextFontDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextFont{vEventIndex};vTextFontDes{$Size}) INSERT IN ARRAY(vTextSizeDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextSize{vEventIndex};vTextSizeDes{$Size}) INSERT IN ARRAY(vTextStyleDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextStyle{vEventIndex};vTextStyleDes{$Size}) INSERT IN ARRAY(vTextColorDes;$Size;1) GET PROCESS VARIABLE(<>DragDemo;vTextColor{vEventIndex};vTextColorDes{$Size}) // Inform source: item to remove vEventIndex:=-2 // ask eALP process to delete selected row VARIABLE TO VARIABLE(<>DragDemo;vEventIndex;vEventIndex) CALL PROCESS(<>DragDemo) Area_Refresh (Self->) End if // valid date End if //$SourceProcessID=-eALP End case
The process communication stuff is managed by the source form method (Outside Call event) in response to the destination area calls:
Case of : (vEventIndex=-1) // after a drag and drop: get selected row vEventIndex:=AL_GetAreaLongProperty (eALP;ALP_Area_SelRow) // selected row : (vEventIndex=-2) // delete row vEventIndex:=AL_GetAreaLongProperty (eALP;ALP_Area_SelRow) // selected row Case of // playing safe : (vEventIndex<1) : (vEventIndex>Size of array(vTextDesc)) Else DELETE FROM ARRAY(vTextDesc;vEventIndex) DELETE FROM ARRAY(vTextTime;vEventIndex) DELETE FROM ARRAY(vTextFont;vEventIndex) DELETE FROM ARRAY(vTextSize;vEventIndex) DELETE FROM ARRAY(vTextStyle;vEventIndex) DELETE FROM ARRAY(vTextColor;vEventIndex) End case AL_SetAreaLongProperty (eALP;ALP_Area_UpdateData;0) // refresh area End case
Here are the resulting forms, after dropping a few events: