- Allow NullDate in TDateEdit when user clears the text.
- Always set Text to a proper value when leaving the control.
Issue 

git-svn-id: trunk@53938 -
This commit is contained in:
bart 2017-01-13 15:20:53 +00:00
parent cd884d710b
commit afa3922372

View File

@ -565,6 +565,7 @@ type
function GetDefaultGlyphName: String; override;
procedure ButtonClick; override;
procedure EditDblClick; override;
procedure EditEditingDone; override;
procedure SetDirectInput(AValue: Boolean); override;
procedure RealSetText(const AValue: TCaption); override;
procedure SetDateMask; virtual;
@ -1625,6 +1626,7 @@ begin
if FocusOnButtonClick then FocusAndMaybeSelectAll;
end;
procedure TDateEdit.EditDblClick;
begin
inherited EditDblClick;
@ -1632,6 +1634,19 @@ begin
ButtonClick;
end;
procedure TDateEdit.EditEditingDone;
var
AText: String;
begin
inherited EditingDone;
if DirectInput then
begin
AText := DateToText(GetDate);
if AText <> Text then //avoid unneccesary recalculation FDate
Text := AText;
end;
end;
procedure TDateEdit.SetDirectInput(AValue: Boolean);
var
Def: TDateTime;
@ -1967,10 +1982,20 @@ begin
Def := FDate;
ADate := Trim(Text);
//if not DirectInput then FDate matches the Text, so no need to parse it
if (ADate <> '') and DirectInput then
if {(ADate <> '') and} DirectInput then
begin
Result := TextToDate(ADate, Def);
FDate := Result;
if (ADate = '') then
begin
if FDefaultToday then
Result := SysUtils.Date
else
Result := NullDate;
end
else
begin
Result := TextToDate(ADate, Def);
FDate := Result;
end;
end
else
Result := Def;