lcl: in TDBLookupListBox update record when selection is changed (Delphi compatible)

git-svn-id: trunk@30414 -
This commit is contained in:
blikblum 2011-04-21 15:35:38 +00:00
parent f27bef2075
commit 5bd27bfb26
4 changed files with 53 additions and 27 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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