寻求日期控件(数据库感知,年月日,年月,年,三个控件)(90分)

  • 主题发起人 主题发起人 small pig
  • 开始时间 开始时间
S

small pig

Unregistered / Unconfirmed
GUEST, unregistred user!
[red]如题,EMail:ah_wcw@163.com,谢谢[/red][:)][:)]
 
Ehlib就可以了~~

其中的datetime控件可以设置mask,就可以了
 
unit EVDBDateTimePicker;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
ComCtrls,dbctrls,db;

type
TEVDBDateTimePicker = class(TDateTimePicker)
private
FDataLink : TFieldDataLink;
FCloseUP : TNotifyEvent;

function GetReadOnly: Boolean;
procedure SetReadOnly(Value: Boolean);

function GetDataField: string;
function GetDataSource: TDataSource;
procedure SetDataField(const Value : string);
procedure SetDataSource(Value: TDatasource);
procedure DataChange(Sender: TObject);
procedure UpdateData(Sender: TObject);

procedure CloseUp(Sender: TObject);
procedure CMExit (var Message: TWMNoParams); message CM_EXIT;
procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
{ Private declarations }
protected
procedure KeyDown ( var Key: word; shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure Change; override;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function ExecuteAction(Action: TBasicAction): Boolean; override;
function UpdateAction(Action: TBasicAction): Boolean; override;
{ Public declarations }
published
Property Caption;
property Datasource : TDataSource read GetDatasource write SetDatasource;
property DataField: string read GetDataField write SetDataField;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Evon', [TEVDBDateTimePicker]);
end;

constructor TEVDbDateTimePicker.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnUpdateData := UpdateData;
FCloseUP := OnCloseUp;
OnCloseUp := CloseUP;
end;

destructor TEVDbDateTimePicker.Destroy;
begin
FDataLink.OnDataChange:=nil;
FDataLink.Free;
inherited Destroy;
end;

function TEVDbDateTimePicker.GetReadOnly: Boolean;
begin
Result := FDataLink.ReadOnly;
end;

procedure TEVDbDateTimePicker.SetReadOnly(Value: Boolean);
begin
FDataLink.ReadOnly := Value;
end;

function TEVDbDateTimePicker.GetDataField: string;
begin
Result:=FDataLink.fieldname;
end;

function TEVDbDateTimePicker.GetDataSource:TDataSource;
begin
Result:=FDataLink.DataSource;
end;

Procedure TEVDbDateTimePicker.SetDataField(const value: string);
begin
FDataLink.FieldName:=Value;
end;

procedure TEVDbDateTimePicker.SetDataSource(Value: TDataSource);
begin
FDataLink.DataSource := Value;
if Value <> nil then Value.FreeNotification(Self);
end;

procedure TEVDbDateTimePicker.DataChange(Sender: TObject);
begin
if FDataLink.field = nil then dateTime :=0
else
if FDataLink.Field.AsVariant <> null then
DateTime:=FDataLink.Field.AsDateTime;
end;

procedure TEVDbDateTimePicker.UpdateData(Sender: TObject);
begin
if FDataLink.CanModify then FDataLink.Field.AsDateTime:=Datetime;
end;

procedure TEVDbDateTimePicker.Change;
begin
if FDataLink.Editing then
begin
UPdateData(Self);
FDataLink.modified;
end;
inherited;
end;

procedure TEVDbDateTimePicker.KeyDown(var Key: word; Shift:TshiftState);
begin
inherited KeyDown(Key, Shift);
if (Key = VK_DELETE) or ((Key = VK_INSERT) and (ssShift in Shift)) then
FDataLink.Edit;
end;

procedure TEVDbDateTimePicker.KeyPress(var Key: Char);
begin
if FDataLink.CanModify then
begin
inherited KeyPress(Key);
case Key of
^H, ^V, ^X, #32..#255:FDataLink.Edit;
#27:
begin
FDataLink.Reset;
Key := #0;
end;
end;
end else Key := #0;
end;

procedure TEVDbDateTimePicker.CMExit(Var Message: TWMNoParams);
begin
try
FdataLink.UpdateRecord;
except
SetFocus;
Raise;
end;
inherited;
end;

procedure TEVDbDateTimePicker.CloseUp(Sender: TObject);
begin
if Not FDataLink.CanModify then FdataLink.Reset
else FdataLink.Edit;
if Assigned(FCloseUP) then FCloseUP(Self);
end;

function TEVDbDateTimePicker.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or (FDataLink <> nil) and
FDataLink.ExecuteAction(Action);
end;

function TEVDbDateTimePicker.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or (FDataLink <> nil) and
FDataLink.UpdateAction(Action);
end;

procedure TEVDbDateTimePicker.CMGetDataLink(var Message: TMessage);
begin
Message.Result := Integer(FDataLink);
end;

end.

请给分! 谢谢!
 
为什么用控件,看我的
procedure TMainFrm.Timer1Timer(Sender: TObject);
begin
StatusBar.Panels[3].Text :=
FormatDateTime('"当前时间" yyyy"年"m"月"d"日" hh:mm:ss AM/PM dddd', Now);
end;
格式想怎么变怎么变
实在要作,你可以用Edit等模拟出时间控件
 
如上,不需要使用控件就可以实现了
 
直接用DateTimePicker就行了
 
http://www.vclxx.org/DELPHI/AAAT1022.HTM
深度历险数据库相关控,好像有这个控件

 
实际上如果可以自己改写一个datetime得控件搞定了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
844
DelphiTeacher的专栏
D
后退
顶部