26
26
//update the caption on next record etc...
27
27
procedure TDBEdit.DataChange(Sender: TObject);
29
DataLinkField: TField;
29
if FDataLink.Field <> nil then begin
30
//use the right EditMask if any
31
//EditMask := FDataLink.Field.EditMask; doesn't exist yet
32
Alignment := FDataLink.Field.Alignment;
31
DataLinkField := FDataLink.Field;
32
if DataLinkField <> nil then begin
33
//use Field EditMask by default
34
if not FCustomEditMask then
35
EditMask := DataLinkField.EditMask;
36
Alignment := DataLinkField.Alignment;
34
38
//if we are focused its possible to edit,
35
39
//if the field is currently modifiable
36
40
if Focused and FDataLink.CanModify then begin
37
41
//display the real text since we can modify it
38
RestoreMask(FDatalink.Field.Text);
42
RestoreMask(DatalinkField.Text);
41
44
//otherwise display the pretified/formated text since we can't
42
DisableMask(FDataLink.Field.DisplayText);
43
if (FDataLink.Field.DataType = ftString) and (MaxLength = 0) then
44
MaxLength := FDatalink.Field.Size;
45
DisableMask(DataLinkField.DisplayText);
46
if (DataLinkField.DataType in [ftString, ftFixedChar, ftWidestring, ftFixedWideChar])
47
and (MaxLength = 0) then
48
MaxLength := DatalinkField.Size;
47
//todo: uncomment this when TField implements EditMask
53
procedure TDBEdit.ActiveChange(Sender: TObject);
55
if FDatalink.Active then
63
procedure TDBEdit.LayoutChange(Sender: TObject);
51
if not FCustomEditMask then
68
58
procedure TDBEdit.UpdateData(Sender: TObject);
78
68
//the changes have been validated
80
70
FDataLink.Field.Text := Text;
81
//FDataLink.Field.AsString := Text;// I shouldn't have to do this, but text seems broken
84
procedure TDBEdit.FocusRequest(Sender: TObject);
86
//the FieldLink has requested the control
87
//recieve focus for some reason..
88
//perhaps an error occured?
92
73
function TDBEdit.GetDataField: string;
125
106
ChangeDataSource(Self,FDataLink,Value);
128
function TDBEdit.IsReadOnly: boolean;
130
// This function in unneccesary for fpc versions > 2.2.4.
131
// In those versions FDatalink.CanModify already checks if the dataset is active.
132
// So this temporary method should be removed in the future, and the calls to
133
// 'not IsReadOnly' should then be replaced by calls to FDatalink.CanModify.
134
If FDatalink.Active then
135
Result := not FDatalink.CanModify
140
109
procedure TDBEdit.CMGetDataLink(var Message: TLMessage);
142
111
Message.Result := PtrUInt(FDataLink);
146
115
procedure TDBEdit.KeyDown(var Key: Word; Shift: TShiftState);
148
117
inherited KeyDown(Key,Shift);
149
if Key=VK_ESCAPE then begin
150
//cancel out of editing by reset on esc
155
if Key in [VK_DELETE, VK_BACK] then begin
156
if not IsReadOnly then
121
//cancel out of editing by reset on esc
128
if not FieldIsEditable(FDatalink.Field) or not FDataLink.Edit then
163
procedure TDBEdit.KeyPress(var Key: char);
164
function CanAcceptKey(AKey: char): boolean;
166
Result := (Field<>nil) and Field.IsValidChar(AKey) and
167
(Field.DataType<>ftAutoInc);
134
procedure TDBEdit.UTF8KeyPress(var UTF8Key: TUTF8Char);
173
inherited KeyPress(Key);
174
//TCustomMaskEdit sets all normal Keys (and BackSpace) to #0 if IsMasked
175
//but not if control is ReadOnly
176
if (not IsMasked) or (inherited ReadOnly) then
180
if not IsReadOnly then
185
#32..#255: //standard keys
186
if not IsReadOnly and CanAcceptKey(Key) then
138
inherited UTF8KeyPress(UTF8Key);
139
//If the pressed key is unicode then map the char to #255
140
//Necessary to keep the TField.IsValidChar check
141
if Length(UTF8Key) = 1 then
142
CharKey := UTF8Key[1]
146
//handle standard keys
147
if CharKey in [#32..#255] then
196
if not IsReadOnly then
198
#32..#255: //standard keys
199
if not IsReadOnly and CanAcceptKey(SavedKey) then
149
if not FieldCanAcceptKey(FDataLink.Field, CharKey) or not FDatalink.Edit then
205
procedure TDBEdit.Loaded;
208
//need to make sure the state is updated on first load
209
if (csDesigning in ComponentState) then
213
procedure TDBEdit.Notification(AComponent: TComponent;
214
Operation: TOperation);
154
procedure TDBEdit.Notification(AComponent: TComponent; Operation: TOperation);
216
156
inherited Notification(AComponent, Operation);
217
157
// if the datasource is being removed then we need to make sure
226
166
function TDBEdit.EditCanModify: Boolean;
228
168
//should follow the FieldLink for this one
229
Result := FDataLink.Edit;
169
Result := FDataLink.CanModify;
232
172
function TDBEdit.GetEditText: string;
260
200
procedure TDBEdit.WMSetFocus(var Message: TLMSetFocus);
262
202
inherited WMSetFocus(Message);
203
// some widgetsets do not notify clipboard actions properly. Put at edit state at entry
204
if WidgetSet.GetLCLCapability(lcReceivesLMClearCutCopyPasteReliably) = LCL_CAPABILITY_YES then
266
210
procedure TDBEdit.WMKillFocus(var Message: TLMKillFocus);
285
procedure TDBEdit.LMPasteFromClip(var Message: TLMessage);
287
if not IsReadOnly then
289
inherited LMPasteFromClip(Message);
292
procedure TDBEdit.LMCutToClip(var Message: TLMessage);
294
if not IsReadOnly then
296
inherited LMCutToClip(Message);
229
procedure TDBEdit.WndProc(var Message: TLMessage);
236
if FDataLink.CanModify then
238
//LCL changes the Text before LM_PASTE is called and not after like Delphi. Issue 20330
239
//When Edit is called the Text property is reset to the previous value
240
//Add a workaround while bug is not fixed
241
FDataLink.OnDataChange := nil;
244
FDataLink.OnDataChange := @DataChange;
245
inherited WndProc(Message);
249
inherited WndProc(Message);
299
253
{ Public Methods }
304
258
FDataLink.Control := Self;
305
259
FDataLink.OnDataChange := @DataChange;
306
260
FDataLink.OnUpdateData := @UpdateData;
307
FDataLink.OnActiveChange := @ActiveChange;
308
FDataLink.OnLayoutChange := @LayoutChange;
311
263
destructor TDBEdit.Destroy;
315
266
inherited Destroy;