mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-03 03:29:32 +01:00
lcl: in TDBLookupListBox update record when selection is changed (Delphi compatible)
git-svn-id: trunk@30414 -
This commit is contained in:
parent
f27bef2075
commit
5bd27bfb26
@ -373,9 +373,6 @@ Type
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure Click; override;
|
||||
procedure EditingDone; override;
|
||||
|
||||
property Field: TField read GetField;
|
||||
property DataField: string read GetDataField write SetDataField;
|
||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||
@ -389,7 +386,10 @@ Type
|
||||
TDBListBox = class(TCustomDBListBox)
|
||||
protected
|
||||
procedure DataChange(Sender: TObject); override;
|
||||
procedure DoSelectionChange(User: Boolean); override;
|
||||
procedure UpdateData(Sender: TObject); override;
|
||||
public
|
||||
procedure EditingDone; override;
|
||||
published
|
||||
property Align;
|
||||
property Anchors;
|
||||
@ -454,6 +454,7 @@ Type
|
||||
procedure SetNullValueKey(const AValue: TShortCut);
|
||||
protected
|
||||
procedure DataChange(Sender: TObject); override;
|
||||
procedure DoSelectionChange(User: Boolean); override;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure InitializeWnd; override;
|
||||
procedure UpdateData(Sender: TObject); override;
|
||||
|
||||
@ -135,30 +135,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomDBListBox.Click;
|
||||
begin
|
||||
//make sure we are in modify mode if can edit
|
||||
//so if a user changed the selection it can be
|
||||
//updated, and if not cancel out ala ReadOnly
|
||||
if not FDataLink.Edit then
|
||||
begin
|
||||
// restore value
|
||||
DataChange(self);
|
||||
Exit;
|
||||
end;
|
||||
inherited Click;
|
||||
FDataLink.Modified;
|
||||
end;
|
||||
|
||||
procedure TCustomDBListBox.EditingDone;
|
||||
begin
|
||||
//update record only when loosing focus to keep the ability to cancel
|
||||
//after changing the selection more than one time
|
||||
if not Focused then
|
||||
FDataLink.UpdateRecord;
|
||||
inherited EditingDone;
|
||||
end;
|
||||
|
||||
{ Public Methods }
|
||||
constructor TCustomDBListBox.Create(AOwner: TComponent);
|
||||
begin
|
||||
|
||||
@ -36,9 +36,35 @@ begin
|
||||
ItemIndex := -1;
|
||||
end;
|
||||
|
||||
procedure TDBListBox.DoSelectionChange(User: Boolean);
|
||||
begin
|
||||
if User then
|
||||
begin
|
||||
//make sure we are in modify mode if can edit
|
||||
//so if a user changed the selection it can be
|
||||
//updated, and if not cancel out ala ReadOnly
|
||||
if FDataLink.Edit then
|
||||
FDataLink.Modified
|
||||
else
|
||||
begin
|
||||
// restore value
|
||||
DataChange(Self);
|
||||
//necessary to avoid double call of SelectionChange
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
inherited DoSelectionChange(User);
|
||||
end;
|
||||
|
||||
procedure TDBListBox.UpdateData(Sender: TObject);
|
||||
begin
|
||||
if ItemIndex >= 0 then
|
||||
FDataLink.Field.Text := Items[ItemIndex];
|
||||
end;
|
||||
|
||||
procedure TDBListBox.EditingDone;
|
||||
begin
|
||||
FDataLink.UpdateRecord;
|
||||
inherited EditingDone;
|
||||
end;
|
||||
|
||||
|
||||
@ -58,6 +58,29 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.DoSelectionChange(User: Boolean);
|
||||
begin
|
||||
if User then
|
||||
begin
|
||||
//make sure we are in modify mode if can edit
|
||||
//so if a user changed the selection it can be
|
||||
//updated, and if not cancel out ala ReadOnly
|
||||
if FDataLink.Edit then
|
||||
begin
|
||||
FDataLink.Modified;
|
||||
FDataLink.UpdateRecord;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// restore value
|
||||
DataChange(Self);
|
||||
//necessary to avoid double call of SelectionChange
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
inherited DoSelectionChange(User);
|
||||
end;
|
||||
|
||||
procedure TDBLookupListBox.KeyDown(var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
if FLookup.HandleNullKey(Key, Shift) then
|
||||
|
||||
Loading…
Reference in New Issue
Block a user