mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-08 05:57:24 +01:00
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:
parent
31013e0c42
commit
b73550e311
@ -653,6 +653,8 @@ Type
|
|||||||
protected
|
protected
|
||||||
procedure DataChange(Sender: TObject);
|
procedure DataChange(Sender: TObject);
|
||||||
procedure EditingChange(Sender: TObject);
|
procedure EditingChange(Sender: TObject);
|
||||||
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
|
procedure KeyPress(var Key: char); override;
|
||||||
procedure Notification(AComponent: TComponent;
|
procedure Notification(AComponent: TComponent;
|
||||||
Operation: TOperation); override;
|
Operation: TOperation); override;
|
||||||
procedure Change; override;
|
procedure Change; override;
|
||||||
@ -1322,6 +1324,12 @@ begin
|
|||||||
Link.DataSource.FreeNotification(AControl);
|
Link.DataSource.FreeNotification(AControl);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FieldCanAcceptKey(Field: TField; AKey: char): boolean;
|
||||||
|
begin
|
||||||
|
Result := (Field<>nil) and Field.IsValidChar(AKey) and
|
||||||
|
(Field.DataType<>ftAutoInc);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
RegisterComponents('Data Controls',[TDBNavigator,TDBText,TDBEdit,TDBMemo,
|
RegisterComponents('Data Controls',[TDBNavigator,TDBText,TDBEdit,TDBMemo,
|
||||||
|
|||||||
@ -40,18 +40,8 @@ end;
|
|||||||
|
|
||||||
procedure TCustomDBComboBox.Change;
|
procedure TCustomDBComboBox.Change;
|
||||||
begin
|
begin
|
||||||
//need to override this to make sure the datalink gets notified
|
FDataLink.Modified;
|
||||||
//its been modified, then when post etc, it will call
|
inherited Change;
|
||||||
//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;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -93,6 +83,35 @@ begin
|
|||||||
// ToDo
|
// ToDo
|
||||||
end;
|
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);
|
procedure TCustomDBComboBox.Notification(AComponent: TComponent; Operation: TOperation);
|
||||||
begin
|
begin
|
||||||
inherited Notification(AComponent, Operation);
|
inherited Notification(AComponent, Operation);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user