mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 14:59:30 +02:00
lcl: handle NullValueKey of TDBLookup* in KeyDown event instead of through a global handler. Fixes #19164
git-svn-id: trunk@30329 -
This commit is contained in:
parent
4e77a0efec
commit
3cbd34d275
@ -145,7 +145,6 @@ Type
|
||||
FLookupCache: boolean;
|
||||
FLookupList: TLookupList;
|
||||
FNullValueKey: TShortcut;
|
||||
FOnClearSelection: TNotifyEvent;
|
||||
procedure ActiveChange(Sender: TObject);
|
||||
procedure EditingChange(Sender: TObject);
|
||||
procedure FetchLookupData;
|
||||
@ -157,11 +156,10 @@ Type
|
||||
procedure SetListFieldName(const Value: string);
|
||||
procedure SetListSource(Value: TDataSource);
|
||||
procedure SetLookupCache(const Value: boolean);
|
||||
procedure NullKeyHandler(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
function HandleNullKey(var Key: Word; Shift: TShiftState): Boolean;
|
||||
protected
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
procedure DoClearSelection;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -178,7 +176,6 @@ Type
|
||||
property ListFieldIndex: Integer read FListFieldIndex write FListFieldIndex default 0;
|
||||
property ListSource: TDataSource read GetListSource write SetListSource;
|
||||
property NullValueKey: TShortcut read FNullValueKey write FNullValueKey;
|
||||
property OnClearSelection: TNotifyEvent read FOnClearSelection write FOnClearSelection;
|
||||
end;
|
||||
|
||||
{ TDBEdit }
|
||||
@ -454,10 +451,10 @@ Type
|
||||
procedure SetListFieldIndex(const Value: Integer);
|
||||
procedure SetListSource(const Value: TDataSource);
|
||||
procedure SetLookupCache(const Value: boolean);
|
||||
procedure RemoveSelection(Sender: TObject);
|
||||
procedure SetNullValueKey(const AValue: TShortCut);
|
||||
protected
|
||||
procedure DataChange(Sender: TObject); override;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure InitializeWnd; override;
|
||||
procedure UpdateData(Sender: TObject); override;
|
||||
public
|
||||
@ -769,9 +766,9 @@ Type
|
||||
procedure SetListSource(const Value: TDataSource);
|
||||
procedure SetLookupCache(const Value: boolean);
|
||||
procedure SetNullValueKey(const AValue: TShortCut);
|
||||
procedure RemoveSelection(Sender: TObject);
|
||||
protected
|
||||
procedure InitializeWnd; override;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure UpdateData(Sender: TObject); override;
|
||||
procedure UpdateText; override;
|
||||
public
|
||||
|
@ -75,7 +75,6 @@ begin
|
||||
FHasLookUpField:= False;
|
||||
FListLinkTmpSetActive := False;
|
||||
FLookupCache := False;
|
||||
Application.AddOnKeyDownBeforeHandler(@NullKeyHandler, false);
|
||||
end;
|
||||
|
||||
destructor TDBLookup.Destroy;
|
||||
@ -147,12 +146,17 @@ begin
|
||||
FLookupList := TLookupList.Create;
|
||||
end;
|
||||
|
||||
procedure TDBLookup.NullKeyHandler(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
{
|
||||
Returns True if selection must be cleared
|
||||
If NullKey is detected set Key to VK_UNKNOWN
|
||||
}
|
||||
|
||||
function TDBLookup.HandleNullKey(var Key: Word; Shift: TShiftState): Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
i: Integer;
|
||||
begin
|
||||
if (FNullValueKey=KeyToShortCut(Key, Shift)) then
|
||||
Result:=False;
|
||||
if FNullValueKey=KeyToShortCut(Key, Shift) then
|
||||
begin
|
||||
// null associated field
|
||||
if Assigned(FControlLink) and (FDataFieldNames<>'') and FControlLink.Active then
|
||||
@ -161,11 +165,9 @@ begin
|
||||
for i:=0 to FDataFields.Count-1 do
|
||||
TField(FDataFields[i]).Clear;
|
||||
end else
|
||||
if Assigned(FListLink.DataSet) and FListLink.DataSet.Active and Assigned(FListField) then
|
||||
// associated list is active, clear current selection
|
||||
DoClearSelection;
|
||||
Result:=Assigned(FListLink.DataSet) and FListLink.DataSet.Active and Assigned(FListField);
|
||||
Key:=VK_UNKNOWN;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TDBLookup.Notification(AComponent: TComponent; Operation: TOperation);
|
||||
@ -176,12 +178,6 @@ begin
|
||||
FListSource:= nil;
|
||||
end;
|
||||
|
||||
procedure TDBLookup.DoClearSelection;
|
||||
begin
|
||||
if Assigned(FOnClearSelection) then
|
||||
OnClearSelection(Self);
|
||||
end;
|
||||
|
||||
procedure TDBLookup.LinkGetBookMark;
|
||||
begin
|
||||
FListLinkTmpSetActive := not FListLink.DataSet.Active;
|
||||
|
@ -27,7 +27,6 @@ constructor TDBLookupComboBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLookup:= TDBLookup.Create(Self);
|
||||
FLookup.OnClearSelection:=@RemoveSelection;
|
||||
FDataLink.OnActiveChange:= @ActiveChange;
|
||||
end;
|
||||
|
||||
@ -55,6 +54,17 @@ begin
|
||||
ActiveChange(Self);
|
||||
end;
|
||||
|
||||
procedure TDBLookupComboBox.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
if FLookup.HandleNullKey(Key, Shift) then
|
||||
begin
|
||||
//clear selection
|
||||
ItemIndex := -1;
|
||||
//Text := '';
|
||||
end;
|
||||
inherited KeyDown(Key, Shift);
|
||||
end;
|
||||
|
||||
function TDBLookupComboBox.GetKeyField: string;
|
||||
begin
|
||||
Result := FLookup.KeyField;
|
||||
@ -133,10 +143,3 @@ begin
|
||||
FLookup.NullValueKey := AValue;
|
||||
end;
|
||||
|
||||
procedure TDBLookupComboBox.RemoveSelection(Sender: TObject);
|
||||
begin
|
||||
ItemIndex := -1;
|
||||
Text := '';
|
||||
end;
|
||||
|
||||
|
||||
|
@ -26,7 +26,6 @@ constructor TDBLookupListBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLookup:= TDBLookup.Create(Self);
|
||||
FLookup.OnClearSelection := @RemoveSelection;
|
||||
FDataLink.OnActiveChange:= @ActiveChange;
|
||||
end;
|
||||
|
||||
@ -59,6 +58,19 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
if FLookup.HandleNullKey(Key, Shift) then
|
||||
begin
|
||||
//clear selection
|
||||
if not assigned(FDatalink.DataSet) or not FDatalink.DataSet.Active or
|
||||
not assigned(FDatalink.Field) then
|
||||
GetItemIndex; // a list-only dblookuplist do not automatically update itemindex
|
||||
ItemIndex := -1;
|
||||
end;
|
||||
inherited KeyDown(Key, Shift);
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.InitializeWnd;
|
||||
begin
|
||||
inherited InitializeWnd;
|
||||
@ -141,15 +153,6 @@ begin
|
||||
ActiveChange(Self);
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.RemoveSelection(Sender: TObject);
|
||||
begin
|
||||
if not assigned(FDatalink.DataSet) or not FDatalink.DataSet.Active or
|
||||
not assigned(FDatalink.Field) then
|
||||
GetItemIndex; // a list-only dblookuplist do not automatically update itemindex
|
||||
|
||||
ItemIndex := -1;
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.SetNullValueKey(const AValue: TShortCut);
|
||||
begin
|
||||
FLookup.NullValueKey := AValue;
|
||||
|
Loading…
Reference in New Issue
Block a user