如何让输入日期为空?(200分)

淋雨

Unregistered / Unconfirmed
GUEST, unregistred user!
我用“DBdatetimepicker”控件时,无法输入空日期。很多时候并不需要输入日期,
可系统仍用默认日期输入,请问谁有办法解决这个问题,或帮我编一个日期控件,最
好可以用手写输入,并能判断输入日期正确与否。在此先向帮小弟的各位前辈谢过。
 
rxdateedit
 
有个属性,允许空日期后控件中加一个checkbox

DevExpress的控件TdxDateEdit也可以直接支持空日期
http://www.8421.org有下载
 
给你一个日期控件:
unit SPECDateEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Mask;

type
TDateValidCheck = procedure (Sender: TObject) of object;

type
TSPECDateEdit = class(TMaskEdit)
private
{ Private declarations }
FFontColor: TColor;
FColor: TColor;
FValid :TDateValidCheck; // 日期有效性判断
FValue :TDate; // 当前日期值
FCanEmpty :Boolean; // 是否必须输入日期
FIsEmpty :Boolean; // 没有指定值
FDateFormat:String; // 使用的日期格式
protected
{ Protected declarations }
procedure setValue(dInDate:TDate);
function getValue:TDate;
procedure KeyPress( var Key: Char );override;
procedure setEnabled(pEnabled:Boolean);override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
procedure ValidateEdit; override;
published
{ Published declarations }
property Width default 70;
property DateFormat:String read FDateFormat write FDateFormat;
property Value:TDate read getValue write setValue;
property CanEmpty:Boolean read FCanEmpty write FCanEmpty default true;
property isEmpty:Boolean read FisEmpty write FisEmpty;
property OnValid:TDateValidCheck read FValid write FValid;
end;

implementation

constructor TSPECDateEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
self.FColor :=self.Color;
self.FFontColor :=self.Font.Color;
Self.MaxLength := 10;
Self.EditMask := '0000-00-00;1; ';
Self.Font.Name := '宋体';
Self.Font.Size := 9;
Self.Width := 70;
Self.DateFormat := 'YYYY-MM-DD';
Self.CanEmpty := true;
end;

procedure TSPECDateEdit.setEnabled(pEnabled:Boolean);
begin
inherited;
if self.Ctl3D=true then begin
if pEnabled=false then begin
self.Color:=clBtnFace;
self.Font.Color:=clBlue;
end else begin
self.Color:=FColor;
self.Font.Color:=FFontColor;
end;
end;
end;

procedure TSPECDateEdit.KeyPress( var Key: Char );
begin
if key = #13 then begin
GetParentForm(self).Perform(WM_NEXTDLGCTL,0,0);
Key:=#0;
end;
inherited;
end;

function TSPECDateEdit.getValue:TDate;
begin
result := Self.FValue;
end;

procedure TSPECDateEdit.setValue(dIndate:TDate);
begin
Self.FValue:= dIndate;
Self.Text := FormatDateTime(Self.DateFormat,dIndate);
end;

procedure TSPECDateEdit.ValidateEdit;
var
dDate :TDate;
sOldStr :String;
begin
Self.isEmpty := true;
if Self.CanEmpty=false or not (trim(Self.Text)='- -') then begin
sOldStr := ShortDateFormat;
ShortDateFormat := Self.DateFormat;
try
dDate := StrToDate(Self.text);
Self.FValue := dDate;
Self.isEmpty := false;
except
on EConvertError do Self.SetFocus;
end;
end;
if Self.CanEmpty=true and (trim(Self.Text)='- -') then Self.FValue:=0;
if assigned(FValid) then OnValid(Self);
end;

end.
 
使用外挂控件!
Inforpower or Eh ......

 
补充一下:RX有 DBDateEdit
 
ShowCheckBox属性设为true,前面会出现一个checkbox
则为Null时,不打勾,并变灰
不为Null时,打勾
也可通过把勾去掉给其赋空值
 
老兄,這問題我早就問過了,沒辦法!
我后來還是改用的第三方控件,.....


你要嗎?如果要的話就請留下E-Mail吧,我再寄給你就行了!
 
那个控件?ip3000里有吗?
 
最简单的办法就是另外提供一个按钮, 一点击就是清空日期
Edit;
FieldByName('Fieldname').AsVariant := Null;
Post;
 
第三方控件
 
我的EMAIL:lisuperman@21cn.com,请各位兄弟,特别是SYDAN,把第三方控件送给我,
在此先谢过。
 
我想说的是,你现在用的“DBdatetimepicker”控件本身就具备你需要的功能
方法如我之前所说的
 
用过Ehlib吗?里面有一TDBDateTimeEditEh就能满足你的要求!
到http://202.117.210.31/delphi/下载2.2版吧!
 
多人接受答案了。
 
顶部