Link to home
Start Free TrialLog in
Avatar of wipnav
wipnav

asked on

Handling TDateTimePicker events

Hi,

How can I know when the user presses the escape key, or clicks outside of the control, to close a TDateTimePicker?

I've tried using Keydown to trap the escape key, but can't get it to work.

Regards,

Bill
Avatar of mokule
mokule
Flag of Poland image

try to use OnCloseUp event

procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
begin
  // do whatever
end;
Avatar of Balshe
Balshe

do you want to know if he picked the date? or just if the user has canceled?
Avatar of wipnav

ASKER

I need to know if the user cancelled, either because he pressed escape or clicked somewhere else.
ASKER CERTIFIED SOLUTION
Avatar of Balshe
Balshe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So do like this

var
    PreviousDateTime: TDateTime;


procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
begin
  if DateTimePicker1.DateTime = PreviousDateTime then
    begin
    Memo1.lines.Add('cancelled'); // or whatever
    end;
end;

procedure TForm1.DateTimePicker1DropDown(Sender: TObject);
begin
  PreviousDateTime := DateTimePicker1.DateTime;
end;
Avatar of wipnav

ASKER

Balshe,

I was thinking of some sort of event driven solution, but I think I can use what you suggest.

Thanks,

Bill
Balshe's solution works only once.
Strange You accept it.
Avatar of wipnav

ASKER

It's the concept of simply checking if the date changed, not the actual implementation, that I accepted as a solution.