How can my program respond to changes in TDateTimePicker?

I would like to know how to change the label title when the user selects a specific date from the TDateTimePicker component.

Say for example: If 02/06/2012 was marked on the TDateTimePicker component, the label1 label will become "Hello World", otherwise nothing will happen if it was any other date.

+6
source share
1 answer

You need to write an OnChange event OnChange to select a date. You also need to make sure that this event handler fires when the form shows:

 procedure TForm1.UpdateDateTimeLabel; var SelectedDate, SpecialDate: TDateTime; begin SelectedDate := DateTimePicker1.DateTime; SpecialDate := EncodeDate(2012, 2, 16); if IsSameDay(SelectedDate, SpecialDate) then Label1.Caption := 'Hello World' else Label1.Caption := ''; end; procedure TForm1.DateTimePicker1Change(Sender: TObject); begin UpdateDateTimeLabel; end; procedure TForm1.FormShow(Sender: TObject); begin UpdateDateTimeLabel; end; 
+7
source

Source: https://habr.com/ru/post/908608/


All Articles