I am trying to prevent selection of a date that is less than today in the cxDateNavigator. However when I select the date today I trigger the message. What am I missing here ?
procedure TForm9.cxDateNavigator1SelectionChanged(Sender: TObject; const AStart,
AFinish: TDateTime);
begin
if cxDateNavigator1.Date <Now then
showmessage('yo.');
end;
CodePudding user response:
I don't know the cxDateNavigator control, but I think the problem is that "Now" returns both date and time. A TDateTime variable internally is a number with decimals, the "date" part is stored as integer and the "time" as the decimals. So you should cut off the Time/decimals, so you compare just the Date part without the time. Like this:
procedure TForm9.cxDateNavigator1SelectionChanged(Sender: TObject; const AStart, AFinish: TDateTime);
begin
if Trunc(cxDateNavigator1.Date) < Trunc(Now) then
showmessage('yo.');
end;