diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index 489e61e0d7..8634528d44 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -131,7 +131,6 @@ Type FKeyFields: TList; // Keyfields in lookup dataset FListField: TField; // Result field in lookup dataset FListKeys: array of Variant; - FLookupList: TLookupList; FNullValueKey: TShortcut; FHasLookUpField: Boolean; FListLinkTmpSetActive: Boolean; @@ -159,6 +158,7 @@ Type function KeyFieldValue: Variant; procedure UpdateData(ValueIndex: Integer); function GetKeyValue(ValueIndex: Integer): Variant; + function GetKeyIndex: Integer; function GetKeyIndex(const AKeyValue: Variant): Integer; property LookupCache: boolean read FLookupCache write SetLookupCache; // properties to be published by owner control diff --git a/lcl/include/dblookup.inc b/lcl/include/dblookup.inc index c269ba487c..d49f9cb46c 100644 --- a/lcl/include/dblookup.inc +++ b/lcl/include/dblookup.inc @@ -78,7 +78,6 @@ begin FDataFields.Destroy; FKeyFields.Destroy; FListLink.Destroy; - FLookupList.Free; inherited Destroy; end; @@ -138,8 +137,6 @@ end; procedure TDBLookup.SetLookupCache(const Value: boolean); begin FLookupCache := Value; - if (Value and not Assigned(FLookupList)) then - FLookupList := TLookupList.Create; end; { @@ -214,17 +211,12 @@ begin Exit; LinkGetBookMark; try - if FLookupCache then - FLookupList.Clear; FListLink.DataSet.First; SetLength(FListKeys, FListLink.Dataset.RecordCount); i := 0; while not FListLink.DataSet.EOF do begin - if (FLookupCache and not FLookUpFieldIsCached) then - FLookupList.Add(FListLink.DataSet.FieldValues[FKeyFieldNames], - FListField.Value); - s:=FListField.DisplayText; + s := FListField.DisplayText; FListKeys[i] := FListLink.DataSet.FieldValues[FKeyFieldNames]; Inc(i); FControlItems.Add(s); @@ -344,34 +336,15 @@ begin if not FControlLink.Active or (ValueIndex < 0) or (ValueIndex >= Length(FListKeys)) then Exit; Key := FListKeys[ValueIndex]; - if FLookupCache and not FLookupFieldIsCached then - begin - if not VarIsNull(Key) then + + FControlLink.Edit; + if FDataFields.Count = 1 then + TField(FDataFields[0]).Value := Key + else begin - FControlLink.DataSet.Edit; - if FDataFields.Count = 1 then - TField(FDataFields[0]).Value := Key - else - begin - for I := 0 to FDataFields.Count -1 do - TField(FDataFields[I]).Value := Key[I]; - end; - end; - Exit; - end; - if not (Assigned(FListLink.DataSet) and Assigned(FListField)) then - Exit; - LinkGetBookMark; - try - if FListLink.DataSet.Locate(FKeyFieldNames, Key, []) then - begin - FControlLink.DataSet.Edit; for I := 0 to FDataFields.Count -1 do - TField(FDataFields[I]).Value := TField(FKeyFields[I]).Value; + TField(FDataFields[I]).Value := Key[I]; end; - finally - LinkGotoBookMark; - end; end; function TDBLookup.GetKeyValue(ValueIndex: Integer): Variant; @@ -382,6 +355,14 @@ begin Result := FListKeys[ValueIndex]; end; +function TDBLookup.GetKeyIndex: Integer; +begin + if Assigned(FControlLink) and FControlLink.Active and (FDataFieldNames <> '') then + Result := GetKeyIndex(FControlLink.DataSet.FieldValues[FDataFieldNames]) + else + Result := -1; +end; + function TDBLookup.GetKeyIndex(const AKeyValue: Variant): Integer; begin Result := 0; diff --git a/lcl/include/dblookupcombobox.inc b/lcl/include/dblookupcombobox.inc index 52395af0ed..10a7158e81 100644 --- a/lcl/include/dblookupcombobox.inc +++ b/lcl/include/dblookupcombobox.inc @@ -47,7 +47,7 @@ var i: Integer; begin if FDatalink.Active then - i := FLookup.GetKeyIndex(FLookup.KeyFieldValue) + i := FLookup.GetKeyIndex else i := -1; ItemIndex := i; @@ -154,7 +154,7 @@ begin if ([csLoading, csDestroying] * ComponentState) = [] then begin FLookup.Initialize(FDataLink, Items); - i := FLookup.GetKeyIndex(FLookup.KeyFieldValue); + i := FLookup.GetKeyIndex; ItemIndex := i; if i = -1 then Text := ''; diff --git a/lcl/include/dblookuplistbox.inc b/lcl/include/dblookuplistbox.inc index b6e45f99c6..2702e28b02 100644 --- a/lcl/include/dblookuplistbox.inc +++ b/lcl/include/dblookuplistbox.inc @@ -44,7 +44,7 @@ end; procedure TDBLookupListBox.DataChange(Sender: TObject); begin if FDatalink.Active then - ItemIndex := FLookup.GetKeyIndex(FLookup.KeyFieldValue) + ItemIndex := FLookup.GetKeyIndex else ItemIndex := -1; end; @@ -157,7 +157,7 @@ begin if [csLoading, csDestroying] * ComponentState = [] then begin FLookup.Initialize(FDataLink, Items); - ItemIndex := FLookup.GetKeyIndex(FLookup.KeyFieldValue); + ItemIndex := FLookup.GetKeyIndex; end; end;