Recent

Author Topic: Bold Specific Dates Calendar Component  (Read 1063 times)

khoward

  • New Member
  • *
  • Posts: 39
Bold Specific Dates Calendar Component
« on: May 28, 2020, 04:35:42 pm »
Hello everyone,
Just a casual hobby programmer here.
Was wanting to create a task scheduling app (very basic) where tasks are stored in a database of some sort (SQLite most likely).I would like to read the current months activities from the database and bold specific days on a calendar (month view) to indicate that there is a task scheduled for that day.  That part seems easy enough as there are many tutorials on working with databases.

So, this is my question: what component can I use, for my novice skillset, that would allow me to bold specific days?Regular old TCalendar seems to be too limited....
Orpheus, CalLite, VisualPlanit?
Has anyone done this before?  Would you mind providing a code example?
Thanks in advance!
Keith

jamie

  • Hero Member
  • *****
  • Posts: 3528
Re: Bold Specific Dates Calendar Component
« Reply #1 on: May 28, 2020, 04:53:40 pm »
Try making a calendar using the TDrawGrid or maybe even the TStringGrid. both allow you to custom draw the cells and you can customize the grid lines etc..

The only true wisdom is knowing you know nothing

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #2 on: May 28, 2020, 04:59:55 pm »
Jamie,

Hmmm....didn't consider that component.Sounds interesting as I could derive my own class from these and expand from there.Dunno if I'm up for the challenge, but, it could be good learning experience!Thanks for the reply.  :)

wp

  • Hero Member
  • *****
  • Posts: 7544
Re: Bold Specific Dates Calendar Component
« Reply #3 on: May 28, 2020, 05:06:55 pm »
TCalLite has been made for such a request. Of course TvPlanit would be more advanced, but it is more complicated. Both components are available through OPM.

See the wiki
CalLite: https://wiki.lazarus.freepascal.org/CalLite and https://wiki.lazarus.freepascal.org/CalLite:_Usage
TvPlanIt: https://wiki.freepascal.org/Turbopower_Visual_PlanIt

In order to paint a specific date in bold in CalLite write a handler for the OnPrepareCanvas event - see Demo2.
« Last Edit: May 28, 2020, 05:48:37 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #4 on: May 28, 2020, 06:31:44 pm »
WP,
Ah!  Thanks!  That was EXACTLY what I was looking for!Where do I find Demo2, please?
Again, many thanks!
Keith

wp

  • Hero Member
  • *****
  • Posts: 7544
Re: Bold Specific Dates Calendar Component
« Reply #5 on: May 28, 2020, 06:34:59 pm »
After installation of CalLite you find the demo projects directly in the installation folder.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #6 on: May 28, 2020, 06:36:01 pm »
Wp,
Disregard my last post as I think I found it.Demo 2 is in with the component package for CalLite, right?
Whoa your fast!  You answered before I could....thanks again! :D

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #7 on: May 29, 2020, 08:21:20 pm »
Mr. Werner,
Sorry to be a pest, but I looked at Demo 2 and it has a default calendar that appears to not be themed.There is another calendar that is themed but is placed down and to the right (out of bounds) of the form.I correct the code to be able to see the themed calendar (both of which look very nice!), but I'm failing to understand how to relate what I need to your post.I looked at the source for CalLite and it looks like handling for holidays is "baked in", so to speak.This is most useful when trying to schedule an appointment on a day that is a "holiday" and then popping up a message box stating that one can not schedule on this day, because it is a holiday.But, how do I bold specific dates?  Especially ones that are not holidays?  Like days that have appointments scheduled (not a holiday).
And, can I read from a database and set holiday dates in one go, or do I have to call CalendarLite.AddHoliday() for each date?
Sorry for being such a rank amateur... :-[

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #8 on: May 29, 2020, 08:24:34 pm »
To be a little more clear, what is onPrepareCalendar (purpose)?  How do I use it?  How does this relate to holidays?  How does it relate to non-holidays?

wp

  • Hero Member
  • *****
  • Posts: 7544
Re: Bold Specific Dates Calendar Component
« Reply #9 on: May 29, 2020, 10:38:30 pm »
Sorry, maybe the example was too complex. I am attaching a simpler one: in the OnCreate event of the form, an array is filled with random dates, and all dates in this array will be drawn in bold and blue font.

OnPrepareCanvas is an event provided by the calendar. It is called during the painting cycle iterating over all days of the currently displayed month. For each day (i.e. each cell in the calendar) the procedure assigned to this event is called. The event provides the currently painted date as parameter. The event handler must check whether this date is one of the "bold dates". If it is, the font of the calendar can be set to bold and blue color.

As you see, this mechanism is not related to holidays, it can be applied to any dates.

[EDIT]
Replaced the attachment... Sorry.
« Last Edit: June 01, 2020, 03:28:33 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #10 on: June 01, 2020, 02:31:23 pm »
Mr. Werner,Thank you very much for your additional time and effort!  I will study this later today.Your time and kindness is very appreciated.
Keith

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #11 on: June 01, 2020, 03:03:54 pm »
Mr. Werner,
This looks like a simple example on how to programmatically change the height of the combobox.I don't see anything assigned for the form's onCreate event.  Actually, I don't see a reference to calLite in the uses block....perhaps this was meant for another user?

So, I can create an array and assign that array to the calLite instance to bold them....perfect!  Would this be a simple array of type integer? 

How do I assign this array to the calendar instance?
Does this get passed to the onPrepareCanvas method?

I see in Demo2 that the TForm1 has a PrepareCanvas method and it looks like earlier in the code that the demoCal.onPrepareCanvas is assigned to the address of this, correct?
I do see that the formatting is changed here in this method.

I'm starting to understand a bit, but, I still don't know how to put it all together....OnPrepareCanvas seems to take an object, a canvas, word data types that represent the date component and a cell state....but no array.Just need some help on how to construct (type) and how to connect that array (assign to cal instance or pass to onPrepareCanvas method).

Thanks again!
Keith

wp

  • Hero Member
  • *****
  • Posts: 7544
Re: Bold Specific Dates Calendar Component
« Reply #12 on: June 01, 2020, 03:36:48 pm »
Mr. Werner,
This looks like a simple example on how to programmatically change the height of the combobox.I don't see anything assigned for the form's onCreate event.  Actually, I don't see a reference to calLite in the uses block....perhaps this was meant for another user?
Sorry, I work on too many posts simultaneously, not good... Now I deleted the attachment and added to correct one. I hope this also answers your questions.

The "object" passed along with an event, here in the OnPrepareCanvas, tells the calling routine which object sent the event (therefore, it is called "Sender"). While mostly being ignored the parameter is helpful when several components share the same event handler.

The array is completely independent of the CalLite component, it's just an example. You could use a database table or a stringgrid, or whatever. The point is that the OnPrepareCanvas event handler gets the date of the calendar cell currently being drawn it only must look up in the array/database/stringgrid/or whatever, whether this date is among the stored ones.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Zoran

  • Hero Member
  • *****
  • Posts: 1590
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Bold Specific Dates Calendar Component
« Reply #13 on: June 01, 2020, 04:16:19 pm »
There is also a nice example project in the wiki: https://wiki.lazarus.freepascal.org/CalLite:_Flag_days_in_Finland

khoward

  • New Member
  • *
  • Posts: 39
Re: Bold Specific Dates Calendar Component
« Reply #14 on: June 01, 2020, 05:04:50 pm »
Quote
Sorry, I work on too many posts simultaneously, not good...
No problem, I understand.
I'm am just very grateful that you took time out of your busy day to help me.  This will help others as well.
I looked at your example and understand MUCH better....I was thinking that only a month of days would get handled at a time and that an event would get fired when the buttons to advance or decrement the month was pressed, thus updating the calendars month view.
Thank you! :D This helped immensely!
Keith

 

TinyPortal © 2005-2018