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
LVL 1
wipnavAsked:
Who is Participating?
 
BalsheConnect With a Mentor Commented:
is this usefull:

 T:TDate;
implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);


begin

  t:=DateTimePicker1.Date;

end;

procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
begin
  if t=DateTimePicker1.Date then
ShowMessage('User Canceled');
end;

??


0
 
mokuleCommented:
try to use OnCloseUp event

procedure TForm1.DateTimePicker1CloseUp(Sender: TObject);
begin
  // do whatever
end;
0
 
BalsheCommented:
do you want to know if he picked the date? or just if the user has canceled?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
wipnavAuthor Commented:
I need to know if the user cancelled, either because he pressed escape or clicked somewhere else.
0
 
mokuleCommented:
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;
0
 
wipnavAuthor Commented:
Balshe,

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

Thanks,

Bill
0
 
mokuleCommented:
Balshe's solution works only once.
Strange You accept it.
0
 
wipnavAuthor Commented:
It's the concept of simply checking if the date changed, not the actual implementation, that I accepted as a solution.
0
All Courses

From novice to tech pro — start learning today.