The control code:
The unit DBDateTime;
Interface
USES the
SysUtils, Classes, Controls, ComCtrls DBCtrls, DB, Windows, Messages, Dialogs.
Type
TDBDateTime=class (TDateTimePicker)
Private
FDataLink: TFieldDataLink;
FAlignment: TAlignment;
Procedure SetAlignment (const Value: TAlignment);
Procedure DataChange (Sender: TObject);
Procedure EditingChange (Sender: TObject);
Procedure the UpdateData (Sender: TObject);
The function GetDataField: WideString;
The function GetDataSource: TDataSource;
Procedure SetDataField (const Value: WideString);
Procedure SetDataSource (const Value: TDataSource);
Procedure CMExit (var Message: TCMExit); The message CM_EXIT;
{Private declarations}
Protected
Procedure Change; Override.
Procedure Notification (AComponent: TComponent;
Operation: TOperation); Override.
{Protected declarations}
Public
The constructor Create (AOwner: TComponent); Override.
The destructor Destroy; Override.
{Public declarations}
Published
The property Alignment: TAlignment read FAlignment write SetAlignment;
The property DataField: WideString read GetDataField write SetDataField;
The property DataSource: TDataSource read GetDataSource write SetDataSource;
end;
Procedure Register;
Implementation
Procedure Register;
The begin
RegisterComponents (' Data Controls', [TDBDateTime]);
end;
{TDBDateTime}
Procedure TDBDateTime. Change;
The begin
FDataLink. Modified;
If not FDataLink. Editing then
FdataLink. Edit;
//postmessage (Self. Handle, wm_keydown, VK_RIGHT, 0).
Inherited Change;
end;
Procedure TDBDateTime. CMExit (var Message: TCMExit);
The begin
Try
FDataLink. UpdateRecord;
Except,
//SelectAll;
SetFocus;
Raise;
end;
DoExit;
end;
The constructor TDBDateTime. Create (AOwner: TComponent);
The begin
Inherited the Create (Aowner);
FDataLink:=TFieldDataLink. Create;
FDataLink. Control:=the Self;
FDataLink. OnDataChange:=DataChange;
FDataLink. OnEditingChange:=EditingChange;
FDataLink. OnUpdateData:=the UpdateData;
end;
Procedure TDBDateTime. DataChange (Sender: TObject);
The begin
If FDataLink. Field & lt;> Nil then
The begin
If FDatalink. Field. AsDateTime=0 then DateTime:=1
The else DateTime:=FDatalink Field. AsDateTime;
End the else
The begin
DateTime: now=();
end;
end;
Destructor TDBDateTime. Destroy;
The begin
FDataLink. OnDataChange:=nil;
FDataLink. OnUpdateData:=nil;
FDataLink. Free;
FDataLink:=nil;
Inherited Destroy;
end;
Procedure TDBDateTime. EditingChange (Sender: TObject);
The begin
If (a DataSource & lt;> Nil) and (DataField & lt;> ") then
FDataLink. Edit;
end;
The function TDBDateTime. GetDataField: WideString;
The begin
Result:=FDataLink. FieldName;
end;
The function TDBDateTime. GetDataSource: TDataSource;
The begin
Result:=FDataLink. The DataSource;
end;
Procedure TDBDateTime. Notification (AComponent: TComponent;
Operation: TOperation);
The begin
Inherited Notification (AComponent, Operation);
If (Operation=opRemove) and (FDataLink & lt;> Nil) and
(AComponent=DataSource) then the DataSource:=nil;
end;
Procedure TDBDateTime. SetAlignment (const Value: TAlignment);
Var
Style: DWORD;
The begin
If FAlignment & lt;> The Value then
The begin
FAlignment:=Value;
Style:=GetWindowLong (Handle, GWL_STYLE);
Style:=style and (not ES_LEFT) and (not ES_CENTER) and (not ES_RIGHT);
Case FAlignment of
TaLeftJustify: SetWindowLong (Handle, GWL_STYLE, style or ES_LEFT);
TaRightJustify: SetWindowLong (Handle, GWL_STYLE, style or ES_RIGHT);
TaCenter: SetWindowLong (Handle, GWL_STYLE, style or ES_CENTER);
end;
Invalidate.
end;
end;
Procedure TDBDateTime. SetDataField (const Value: WideString);
The begin
FDataLink. FieldName:=Value;
end;
Procedure TDBDateTime. SetDataSource (const Value: TDataSource);
The begin
If not (FDataLink DataSourceFixed and (csLoading ComponentState) in) then
FDataLink. The DataSource:=Value;
If the Value & lt;> Nil Value. Then FreeNotification (Self);
end;
Procedure TDBDateTime. The UpdateData (Sender: TObject);
The begin
//ShowMessage (DateTimeToStr (DateTime));
FDatalink. Field. AsDateTime:=DateTime;
end;
end.
CodePudding user response:
Using InfoPower date of control,,,