Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TMonthCalender - How to know when date is changed? 1

Status
Not open for further replies.

TimSNL

Programmer
Sep 11, 2001
119
AU
Hello,

I am trying to use a TMonthCalendar to allow the user to select a date on my form. When the user changes the date I need to update some other things on the form.

Problem: I can't work out how to detect when the date in the TMonthCalender has been changed, like an OnChange event.

The OnClick event will tell me when the user changes the date by clicking on one if the days.
But ... if the user changes the month using the dropdown list from the title, or if the user changes the year using the spinner in the title, the OnClick event does not trigger. [talk]

Does anyone know how I can tell when the date is changed no matter what method is used to change it?

Thanks for your help.

Tim
SNL Computing
 
It's a kludge, but you can process the GetMonthInfo event by setting a flag so at least you know that the month might have been changed by the user. Then other events can call a routine to test the flag and take appropriate action.

As an extreme measure, you can trap when the flag goes from false to true and set a timer to read the date after a second or two. The timer event of course would set your other objects, clear the flag and free itself.
 
At the onClick event the value of MonthCalender.Date changes. If the user scrolls the month, and it is let say 9 february, the value stored in the date property will be 9 march.

The way I use it:

procedure MyForm.myCalenderClick (Sender: TObject);
begin
Do_Something;
end;

where in Do_something I process the date value like:

procedure MyForm.Do_Something;
begin
Days := Round(MyCalender.Date - RefDate);
RefSearch := Days mod 20;
MyGrid.Row := RefSearch + 1;
end;

Steven van Els
SAvanEls@cq-link.sr
 
Steven: Read the post again. When the user clicks on the month name (or for that matter, the year number) a new month can be selected without generating a click event. In other words, the user is not clicking on the left and right arrow pushbuttons, he is clicking in the middle between them.

I was not aware of this "feature" until Tim mentioned it. I will have to go back and tighten up one of my apps to deal with it as well.
 
Cool, look what I found! [flip]


The free components from this site are great.

The Calender they have developed is realy nice, and it has an OnDateChanged event.

What do you guys think?

Tim
SNL Computing
 
Zathras, now you mention it, I didn't know it also, and it doesn't generate an onclick event, but another event is fired.

The OnGetMonthInfo event is triggered when:

1) Starting up (display the calender)
2) Using the month arows
3) Using the month dropdown list in the middle

I used a small test program to discover it, 2 labels, a reset button and a calendar

Code:
procedure TForm1.MonthCalendar1Click(Sender: TObject);
begin
   label1.Caption := 'On Click';
end;

procedure TForm1.MonthCalendar1GetMonthInfo(Sender: TObject;
  Month: Cardinal; var MonthBoldInfo: Cardinal);
begin
  label2.Caption := 'Monthclick';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption:= '';
  label2.Caption:= '';
end;



Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top