mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-07 05:29:31 +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
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure Click; override;
|
|
||||||
procedure EditingDone; override;
|
|
||||||
|
|
||||||
property Field: TField read GetField;
|
property Field: TField read GetField;
|
||||||
property DataField: string read GetDataField write SetDataField;
|
property DataField: string read GetDataField write SetDataField;
|
||||||
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
property DataSource: TDataSource read GetDataSource write SetDataSource;
|
||||||
@ -389,7 +386,10 @@ Type
|
|||||||
TDBListBox = class(TCustomDBListBox)
|
TDBListBox = class(TCustomDBListBox)
|
||||||
protected
|
protected
|
||||||
procedure DataChange(Sender: TObject); override;
|
procedure DataChange(Sender: TObject); override;
|
||||||
|
procedure DoSelectionChange(User: Boolean); override;
|
||||||
procedure UpdateData(Sender: TObject); override;
|
procedure UpdateData(Sender: TObject); override;
|
||||||
|
public
|
||||||
|
procedure EditingDone; override;
|
||||||
published
|
published
|
||||||
property Align;
|
property Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
@ -454,6 +454,7 @@ Type
|
|||||||
procedure SetNullValueKey(const AValue: TShortCut);
|
procedure SetNullValueKey(const AValue: TShortCut);
|
||||||
protected
|
protected
|
||||||
procedure DataChange(Sender: TObject); override;
|
procedure DataChange(Sender: TObject); override;
|
||||||
|
procedure DoSelectionChange(User: Boolean); override;
|
||||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
procedure InitializeWnd; override;
|
procedure InitializeWnd; override;
|
||||||
procedure UpdateData(Sender: TObject); override;
|
procedure UpdateData(Sender: TObject); override;
|
||||||
|
|||||||
@ -135,30 +135,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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 }
|
{ Public Methods }
|
||||||
constructor TCustomDBListBox.Create(AOwner: TComponent);
|
constructor TCustomDBListBox.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
|
|||||||
@ -36,9 +36,35 @@ begin
|
|||||||
ItemIndex := -1;
|
ItemIndex := -1;
|
||||||
end;
|
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);
|
procedure TDBListBox.UpdateData(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if ItemIndex >= 0 then
|
if ItemIndex >= 0 then
|
||||||
FDataLink.Field.Text := Items[ItemIndex];
|
FDataLink.Field.Text := Items[ItemIndex];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDBListBox.EditingDone;
|
||||||
|
begin
|
||||||
|
FDataLink.UpdateRecord;
|
||||||
|
inherited EditingDone;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -58,6 +58,29 @@ begin
|
|||||||
end;
|
end;
|
||||||
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);
|
procedure TDBLookupListBox.KeyDown(var Key: Word; Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
if FLookup.HandleNullKey(Key, Shift) then
|
if FLookup.HandleNullKey(Key, Shift) then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user