File: dbdateedit.inc

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (163 lines) | stat: -rw-r--r-- 3,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{%MainUnit ../dbextctrls.pp}

{******************************************************************************
 	This file is part of the Lazarus Component Library (LCL)

 	See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************}
// included by dbextctrls.pp

{ Private Methods }

procedure TDBDateEdit.DataChange(Sender: TObject);
begin
  if (FDataLink.Field <> nil) and (not FDataLink.Field.IsNull) then
    Self.Date := FDataLink.Field.AsDateTime
  else
    Text := '';
end;

procedure TDBDateEdit.UpdateData(Sender: TObject);
begin
  if Text = '' then
    FDataLink.Field.Clear
  else
    FDataLink.Field.AsDateTime := Self.Date;
end;

function TDBDateEdit.GetDataField: string;
begin
  Result := FDataLink.FieldName;
end;

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

function TDBDateEdit.GetField: TField;
begin
  Result := FDataLink.Field;
end;

procedure TDBDateEdit.SetDataField(const Value: string);
begin
  FDataLink.FieldName := Value;
end;

procedure TDBDateEdit.SetDataSource(Value: TDataSource);
begin
  ChangeDataSource(Self, FDataLink, Value);
end;

procedure TDBDateEdit.CMGetDataLink(var Message: TLMessage);
begin
  Message.Result := PtrUInt(FDataLink);
end;

{ Protected Methods}
procedure TDBDateEdit.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if Operation=opRemove then
    if assigned(FDataLink) and (AComponent=DataSource) then
      DataSource:=nil;
end;

function TDBDateEdit.EditCanModify: Boolean;
begin
  Result := FDataLink.CanModify;
end;

procedure TDBDateEdit.EditEnter;
begin
  inherited;
  if not FDataLink.Editing then
    FDataLink.Reset;
end;

procedure TDBDateEdit.EditKeyDown(var Key: Word; Shift: TShiftState);
begin
  inherited;
  case Key of
    VK_ESCAPE:
      //cancel out of editing by reset on Esc
      if FDataLink.Editing then begin
        FDataLink.Reset;
        Key := VK_UNKNOWN;
      end;
    VK_DELETE, VK_BACK:
      if not FDataLink.Edit then
        Key := VK_UNKNOWN;
  end;
end;

procedure TDBDateEdit.EditKeyPress(var Key: Char);
begin
  inherited;
  case Key of
    #32..#255: //standard keys
      if not assigned(FDataLink.Field) or not Field.IsValidChar(Key) or not FDataLink.Edit then
        Key:=#0;
  end;
end;

procedure TDBDateEdit.ButtonClick;
begin
  if not Focused then
    SetFocus;
  if FDataLink.CanModify then
    FDataLink.Edit;
  inherited;
end;

procedure TDBDateEdit.EditChange;
begin
  if FDataLink.Editing then
    FDataLink.Modified;
  inherited;
end;

procedure TDBDateEdit.EditExit;
begin
  inherited;
  if FDataLink.Editing then
    FDataLink.UpdateRecord
  else
    FDataLink.Reset;
end;

procedure TDBDateEdit.Reset;
begin
  FDataLink.Reset;
  inherited;
end;

{ Public Methods }
constructor TDBDateEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := @DataChange;
  FDataLink.OnUpdateData := @UpdateData;
end;

destructor TDBDateEdit.Destroy;
begin
  FDataLink.Destroy;
  inherited Destroy;
end;

function TDBDateEdit.ExecuteAction(AAction: TBasicAction): Boolean;
begin
  Result := inherited ExecuteAction(AAction) or
            assigned(FDataLink) and FDataLink.ExecuteAction(AAction);
end;

function TDBDateEdit.UpdateAction(AAction: TBasicAction): Boolean;
begin
  Result := inherited UpdateAction(AAction) or
            assigned(FDataLink) and FDataLink.UpdateAction(AAction);
end;