Can you test this with TDatetimePicker on something else than Windows 7 ?

Can you test this with TDatetimePicker on something else than Windows 7 ?

Put a DTP and a Memo on a form
set the DTP OnChange event to log its date in the memo

procedure TForm1.DateTimePicker1Change(Sender: TObject);
begin
Memo1.Lines.Add(DateToSTr(DateTimePicker1.Date));
end;

when I select a date, the OnChange event is fired twice.

Worst, if you set Min/MaxDate properties and you click on the dropdown calendar, the OnChange event is fired twice and, the first time, the Date value is the MaxDate !

I've found a workaround, can you test it also ?

type
TDateTimePicker = class(Vcl.ComCtrls.TDateTimePicker)
private
FIgnoreChange: Boolean;
public
procedure WMNotify(var Msg: TWMNotifyDT); message WM_NOTIFY;
procedure Change; override;
end;

procedure TDateTimePicker.WMNotify(var Msg: TWMNotifyDT);
begin
if Msg.NMHdr.code = MCN_SELCHANGE then
FIgnoreChange := True;
inherited;
end;

procedure TDateTimePicker.Change;
begin
if FIgnoreChange then
FIgnoreChange := False;
else
inherited;
end;

Comments

Post a Comment