lazarus的TDBDateEdit控件空值时显示1899.12.30,日期为空值怎样才能显示空白呢?用常规的ataSet.Fields[i].OnGetText方法无效。
解决方法:
打开\lazarus\lcl\EditBtn.pas
找到:function TDateEdit.DateToText(Value: TDateTime): String;
function TDateEdit.DateToText(Value: TDateTime): String; var FS: TFormatSettings; begin if IsNullDate(Value) then Result := '' else begin if (FDateOrder = doNone) or (FFixedDateFormat = '') then begin FS := DefaultFormatSettings; if (FFreeDateFormat <> '') then FS.ShortDateFormat := FFreeDateFormat; Result := DateToStr(Value, FS) end else Result := FormatDateTime(FFixedDateFormat, Value); end; end;
将
if IsNullDate(Value) then
改为:
if (IsNullDate(Value)) or (Value=0) then
function TDateEdit.DateToText(Value: TDateTime): String; var FS: TFormatSettings; begin if (IsNullDate(Value)) or (Value=0) then Result := '' else begin if (FDateOrder = doNone) or (FFixedDateFormat = '') then begin FS := DefaultFormatSettings; if (FFreeDateFormat <> '') then FS.ShortDateFormat := FFreeDateFormat; Result := DateToStr(Value, FS) end else Result := FormatDateTime(FFixedDateFormat, Value); end; end;
修改前:

修改后:


浙公网安备 33010602011771号