LCL: DBLookup controls and ScrollListDataset, scroll also if dataset wwas opened before control was created. Issue #33109, patch from Michal Gawrycki.

git-svn-id: trunk@62415 -
This commit is contained in:
juha 2019-12-18 20:52:05 +00:00
parent 997c17160e
commit 709c6d0859
4 changed files with 38 additions and 9 deletions

View File

@ -133,6 +133,7 @@ Type
FLookUpFieldIsCached: Boolean;
FLookupCache: Boolean;
FInitializing: Boolean;
FScrollListDataset: Boolean;
{$IF FPC_FULLVERSION < 30000}
FFetchingLookupData: Boolean;
{$ENDIF}
@ -154,7 +155,7 @@ Type
destructor Destroy; override;
procedure Initialize(AControlDataLink: TFieldDataLink; AControlItems: TStrings);
function KeyFieldValue: Variant;
procedure UpdateData(ValueIndex: Integer; ScrollDataset: Boolean);
procedure UpdateData(ValueIndex: Integer);
function GetKeyValue(ValueIndex: Integer): Variant;
function GetKeyIndex: Integer;
function GetKeyIndex(const AKeyValue: Variant): Integer;
@ -167,6 +168,7 @@ 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 ScrollListDataset: Boolean read FScrollListDataset write FScrollListDataset;
end;
{ TDBEdit }
@ -448,7 +450,6 @@ Type
TDBLookupListBox = class(TCustomDBListBox)
private
FLookup: TDBLookup;
FScrollListDataset: Boolean;
procedure ActiveChange(Sender: TObject);
function GetKeyField: string;
function GetKeyValue: Variant;
@ -457,6 +458,7 @@ Type
function GetListSource: TDataSource;
function GetLookupCache: boolean;
function GetNullValueKey: TShortCut;
function GetScrollListDataset: Boolean;
procedure SetKeyField(const Value: string);
procedure SetKeyValue(const AValue: Variant);
procedure SetListField(const Value: string);
@ -464,6 +466,7 @@ Type
procedure SetListSource(const Value: TDataSource);
procedure SetLookupCache(const Value: boolean);
procedure SetNullValueKey(const AValue: TShortCut);
procedure SetScrollListDataset(AValue: Boolean);
procedure UpdateLookup;
protected
procedure DataChange(Sender: TObject); override;
@ -531,7 +534,7 @@ Type
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ScrollListDataset: Boolean read FScrollListDataset write FScrollListDataset default False;
property ScrollListDataset: Boolean read GetScrollListDataset write SetScrollListDataset default False;
property ShowHint;
property Sorted;
// property Style;
@ -848,7 +851,6 @@ Type
function IsUnbound: boolean;
private
FLookup: TDBLookup;
FScrollListDataset: Boolean;
procedure ActiveChange(Sender: TObject);
function GetKeyField: string;
function GetKeyValue: variant;
@ -857,6 +859,7 @@ Type
function GetListSource: TDataSource;
function GetLookupCache: boolean;
function GetNullValueKey: TShortCut;
function GetScrollListDataset: Boolean;
procedure SetKeyField(const Value: string);
procedure SetKeyValue(const AValue: variant);
procedure SetListField(const Value: string);
@ -864,6 +867,7 @@ Type
procedure SetListSource(const Value: TDataSource);
procedure SetLookupCache(const Value: boolean);
procedure SetNullValueKey(const AValue: TShortCut);
procedure SetScrollListDataset(AValue: Boolean);
procedure UpdateLookup;
procedure UpdateItemIndex;
protected
@ -945,7 +949,7 @@ Type
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ScrollListDataset: Boolean read FScrollListDataset write FScrollListDataset default False;
property ScrollListDataset: Boolean read GetScrollListDataset write SetScrollListDataset default False;
property ShowHint;
property Sorted;
property Style;

View File

@ -128,6 +128,11 @@ begin
FControlLink := AControlDataLink;
FControlItems := AControlItems;
DoInitialize;
if FScrollListDataset
and Assigned(FListLink) and Assigned(FListLink.DataSet) and FListLink.DataSet.Active
and Assigned(FControlLink) and Assigned(FControlLink.DataSet) and FControlLink.DataSet.Active
then
FListLink.DataSet.Locate(FKeyFieldNames, FControlLink.DataSet.FieldValues[FDataFieldNames], []);
finally
FInitializing := False;
end;
@ -403,7 +408,7 @@ begin
Result := Null;
end;
procedure TDBLookup.UpdateData(ValueIndex: Integer; ScrollDataset: Boolean);
procedure TDBLookup.UpdateData(ValueIndex: Integer);
var
I: Integer;
Key: Variant;
@ -412,7 +417,7 @@ begin
if (ValueIndex < 0) or (ValueIndex >= Length(FListKeys)) then
Exit;
Key := FListKeys[ValueIndex];
if ScrollDataset then
if FScrollListDataset then
FListLink.DataSet.Locate(FKeyFieldNames, Key, []);
if Assigned(FControlLink) and FControlLink.Active then
begin

View File

@ -33,7 +33,7 @@ begin
ItemIndex := Items.IndexOf(Text);
i := ItemIndex;
if i <> -1 then
FLookup.UpdateData(i, FScrollListDataset)
FLookup.UpdateData(i)
else
if FDatalink.EditingSource then
FDatalink.Dataset.Cancel
@ -153,6 +153,11 @@ begin
result := FLookup.NullValueKey;
end;
function TDBLookupComboBox.GetScrollListDataset: Boolean;
begin
Result := FLookup.ScrollListDataset;
end;
procedure TDBLookupComboBox.SetKeyField(const Value: string);
begin
FLookup.KeyField := Value;
@ -193,6 +198,11 @@ begin
FLookup.NullValueKey := AValue;
end;
procedure TDBLookupComboBox.SetScrollListDataset(AValue: Boolean);
begin
FLookup.ScrollListDataset := AValue;
end;
procedure TDBLookupComboBox.UpdateLookup;
begin
if ([csLoading, csDestroying] * ComponentState) = [] then

View File

@ -27,7 +27,7 @@ procedure TDBLookupListBox.UpdateData(Sender: TObject);
begin
if (ItemIndex < 0) then
Exit;
FLookup.UpdateData(ItemIndex, FScrollListDataset);
FLookup.UpdateData(ItemIndex);
end;
function TDBLookupListBox.IsUnbound: boolean;
@ -134,6 +134,11 @@ begin
Result := FLookup.NullValueKey;
end;
function TDBLookupListBox.GetScrollListDataset: Boolean;
begin
Result := FLookup.ScrollListDataset;
end;
procedure TDBLookupListBox.SetKeyField(const Value: string);
begin
FLookup.KeyField:= Value;
@ -174,6 +179,11 @@ begin
FLookup.NullValueKey := AValue;
end;
procedure TDBLookupListBox.SetScrollListDataset(AValue: Boolean);
begin
FLookup.ScrollListDataset := AValue;
end;
procedure TDBLookupListBox.UpdateLookup;
begin
if [csLoading, csDestroying] * ComponentState = [] then