unit DBDateTimePicker;
interface
uses
SysUtils, Classes, Controls, ComCtrls, DBCtrls,
DB, Messages, Windows, Forms;
type
TDBDateTimePicker =
class(TDateTimePicker)
private
FDataLink: TFieldDataLink;
procedure DataChange(Sender: TObject);
procedure EditingChange(Sender: TObject);
function GetDataField:
string;
function GetDataSource: TDataSource;
function GetField: TField;
procedure SetDataField(
const Value:
string);
procedure SetDataSource(Value: TDataSource);
procedure UpdateData (Sender: TObject);
procedure Change;
override;
procedure CMGetDataLink(
var Message: TMessage);
message CM_GETDATALINK;
protected
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
property Field: TField
read GetField;
published
property DataField:
string read GetDataField
write SetDataField;
property DataSource: TDataSource
read GetDataSource
write SetDataSource;
end;
procedure Register;
implementation
constructor TDBDateTimePicker.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csReplicatable];
FDataLink := TFieldDataLink.Create;
FDataLink.Control := Self;
FDataLink.OnDataChange := DataChange;
FDataLink.OnEditingChange := EditingChange;
FDataLink.OnUpdateData := UpdateData;
end;
destructor TDBDateTimePicker.Destroy;
begin
FDataLink.Free;
FDataLink :=
nil;
inherited Destroy;
end;
function TDBDateTimePicker.GetDataSource: TDataSource;
begin
Result := FDataLink.DataSource;
end;
procedure TDBDateTimePicker.SetDataSource(Value: TDataSource);
begin
if not (FDataLink.DataSourceFixed
and (csLoading
in ComponentState))
then
FDataLink.DataSource := Value;
if Value <>
nil then Value.FreeNotification(Self);
end;
function TDBDateTimePicker.GetDataField:
string;
begin
Result := FDataLink.FieldName;
end;
function TDBDateTimePicker.GetField: TField;
begin
Result := FDataLink.Field;
end;
procedure TDBDateTimePicker.SetDataField(
const Value:
string);
begin
FDataLink.FieldName := Value;
end;
procedure TDBDateTimePicker.DataChange(Sender: TObject);
begin
if FDataLink.Field <>
nil then begin
if FDataLink.Field.DataType = ftDate
then DateTime := FDataLink.Field.AsDateTime;
end;
if HandleAllocated
then RedrawWindow(
Handle,
nil, 0, RDW_INVALIDATE
or RDW_ERASE
or RDW_FRAME);
end;
procedure TDBDateTimePicker.EditingChange(Sender: TObject);
begin
end;
procedure TDBDateTimePicker.CMGetDataLink(
var Message: TMessage);
begin
Message.Result := Integer(FDataLink);
end;
procedure TDBDateTimePicker.UpdateData (Sender: TObject);
begin
FDataLink.Field.AsDateTime := DateTime;
end;
procedure TDBDateTimePicker.Change;
begin
FDataLink.Field.DataSet.Edit;
UpdateData(Self);
inherited Change;
end;
procedure Register;
begin
RegisterComponents('
Datensteuerung', [TDBDateTimePicker]);
end;
end.