秋·风

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

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;

修改前:

QQ_1767876098962

修改后:

QQ_1767876167411

 

posted on 2026-01-08 20:44  秋·风  阅读(27)  评论(0)    收藏  举报