lcl: TCustomDBComboBox: put dataset in edit state in KeyDown/Press like TDBEdit. Part of 20326

git-svn-id: trunk@32482 -
This commit is contained in:
blikblum 2011-09-24 00:41:58 +00:00
parent 31013e0c42
commit b73550e311
2 changed files with 39 additions and 12 deletions

View File

@ -653,6 +653,8 @@ Type
protected
procedure DataChange(Sender: TObject);
procedure EditingChange(Sender: TObject);
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: char); override;
procedure Notification(AComponent: TComponent;
Operation: TOperation); override;
procedure Change; override;
@ -1322,6 +1324,12 @@ begin
Link.DataSource.FreeNotification(AControl);
end;
function FieldCanAcceptKey(Field: TField; AKey: char): boolean;
begin
Result := (Field<>nil) and Field.IsValidChar(AKey) and
(Field.DataType<>ftAutoInc);
end;
procedure Register;
begin
RegisterComponents('Data Controls',[TDBNavigator,TDBText,TDBEdit,TDBMemo,

View File

@ -40,18 +40,8 @@ end;
procedure TCustomDBComboBox.Change;
begin
//need to override this to make sure the datalink gets notified
//its been modified, then when post etc, it will call
//updatedata to update the field data with current value
if FDatalink.Active then
if FDatalink.Edit then
begin
FDataLink.Modified;
inherited Change;
end else
UpdateText
else
inherited Change;
FDataLink.Modified;
inherited Change;
end;
@ -93,6 +83,35 @@ begin
// ToDo
end;
procedure TCustomDBComboBox.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
if Key=VK_ESCAPE then begin
//cancel out of editing by reset on esc
FDataLink.Reset;
SelectAll;
Key := VK_UNKNOWN;
end else
if Key in [VK_DELETE, VK_BACK] then begin
if not FDataLink.Edit then
Key := VK_UNKNOWN;
end;
end;
procedure TCustomDBComboBox.KeyPress(var Key: char);
begin
inherited KeyPress(Key);
case Key of
#8: // special keys
if not FDatalink.Edit then
Key:=#0;
#32..#255: //standard keys
if not FieldCanAcceptKey(FDataLink.Field, Key) or not FDatalink.Edit then
Key:=#0;
end;//case
end;
procedure TCustomDBComboBox.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);