lcl: simplified TDBLookup.UpdateData;

remove TDBLookup.FLookupList. Not needed anymore
handle setting Null data

git-svn-id: trunk@34084 -
This commit is contained in:
blikblum 2011-12-10 14:40:25 +00:00
parent 3b2f0d4e32
commit 372a68c92c
4 changed files with 20 additions and 39 deletions

View File

@ -131,7 +131,6 @@ Type
FKeyFields: TList; // Keyfields in lookup dataset FKeyFields: TList; // Keyfields in lookup dataset
FListField: TField; // Result field in lookup dataset FListField: TField; // Result field in lookup dataset
FListKeys: array of Variant; FListKeys: array of Variant;
FLookupList: TLookupList;
FNullValueKey: TShortcut; FNullValueKey: TShortcut;
FHasLookUpField: Boolean; FHasLookUpField: Boolean;
FListLinkTmpSetActive: Boolean; FListLinkTmpSetActive: Boolean;
@ -159,6 +158,7 @@ Type
function KeyFieldValue: Variant; function KeyFieldValue: Variant;
procedure UpdateData(ValueIndex: Integer); procedure UpdateData(ValueIndex: Integer);
function GetKeyValue(ValueIndex: Integer): Variant; function GetKeyValue(ValueIndex: Integer): Variant;
function GetKeyIndex: Integer;
function GetKeyIndex(const AKeyValue: Variant): Integer; function GetKeyIndex(const AKeyValue: Variant): Integer;
property LookupCache: boolean read FLookupCache write SetLookupCache; property LookupCache: boolean read FLookupCache write SetLookupCache;
// properties to be published by owner control // properties to be published by owner control

View File

@ -78,7 +78,6 @@ begin
FDataFields.Destroy; FDataFields.Destroy;
FKeyFields.Destroy; FKeyFields.Destroy;
FListLink.Destroy; FListLink.Destroy;
FLookupList.Free;
inherited Destroy; inherited Destroy;
end; end;
@ -138,8 +137,6 @@ end;
procedure TDBLookup.SetLookupCache(const Value: boolean); procedure TDBLookup.SetLookupCache(const Value: boolean);
begin begin
FLookupCache := Value; FLookupCache := Value;
if (Value and not Assigned(FLookupList)) then
FLookupList := TLookupList.Create;
end; end;
{ {
@ -214,17 +211,12 @@ begin
Exit; Exit;
LinkGetBookMark; LinkGetBookMark;
try try
if FLookupCache then
FLookupList.Clear;
FListLink.DataSet.First; FListLink.DataSet.First;
SetLength(FListKeys, FListLink.Dataset.RecordCount); SetLength(FListKeys, FListLink.Dataset.RecordCount);
i := 0; i := 0;
while not FListLink.DataSet.EOF do while not FListLink.DataSet.EOF do
begin begin
if (FLookupCache and not FLookUpFieldIsCached) then s := FListField.DisplayText;
FLookupList.Add(FListLink.DataSet.FieldValues[FKeyFieldNames],
FListField.Value);
s:=FListField.DisplayText;
FListKeys[i] := FListLink.DataSet.FieldValues[FKeyFieldNames]; FListKeys[i] := FListLink.DataSet.FieldValues[FKeyFieldNames];
Inc(i); Inc(i);
FControlItems.Add(s); FControlItems.Add(s);
@ -344,34 +336,15 @@ begin
if not FControlLink.Active or (ValueIndex < 0) or (ValueIndex >= Length(FListKeys)) then if not FControlLink.Active or (ValueIndex < 0) or (ValueIndex >= Length(FListKeys)) then
Exit; Exit;
Key := FListKeys[ValueIndex]; Key := FListKeys[ValueIndex];
if FLookupCache and not FLookupFieldIsCached then
begin FControlLink.Edit;
if not VarIsNull(Key) then if FDataFields.Count = 1 then
TField(FDataFields[0]).Value := Key
else
begin 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 for I := 0 to FDataFields.Count -1 do
TField(FDataFields[I]).Value := TField(FKeyFields[I]).Value; TField(FDataFields[I]).Value := Key[I];
end; end;
finally
LinkGotoBookMark;
end;
end; end;
function TDBLookup.GetKeyValue(ValueIndex: Integer): Variant; function TDBLookup.GetKeyValue(ValueIndex: Integer): Variant;
@ -382,6 +355,14 @@ begin
Result := FListKeys[ValueIndex]; Result := FListKeys[ValueIndex];
end; 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; function TDBLookup.GetKeyIndex(const AKeyValue: Variant): Integer;
begin begin
Result := 0; Result := 0;

View File

@ -47,7 +47,7 @@ var
i: Integer; i: Integer;
begin begin
if FDatalink.Active then if FDatalink.Active then
i := FLookup.GetKeyIndex(FLookup.KeyFieldValue) i := FLookup.GetKeyIndex
else else
i := -1; i := -1;
ItemIndex := i; ItemIndex := i;
@ -154,7 +154,7 @@ begin
if ([csLoading, csDestroying] * ComponentState) = [] then if ([csLoading, csDestroying] * ComponentState) = [] then
begin begin
FLookup.Initialize(FDataLink, Items); FLookup.Initialize(FDataLink, Items);
i := FLookup.GetKeyIndex(FLookup.KeyFieldValue); i := FLookup.GetKeyIndex;
ItemIndex := i; ItemIndex := i;
if i = -1 then if i = -1 then
Text := ''; Text := '';

View File

@ -44,7 +44,7 @@ end;
procedure TDBLookupListBox.DataChange(Sender: TObject); procedure TDBLookupListBox.DataChange(Sender: TObject);
begin begin
if FDatalink.Active then if FDatalink.Active then
ItemIndex := FLookup.GetKeyIndex(FLookup.KeyFieldValue) ItemIndex := FLookup.GetKeyIndex
else else
ItemIndex := -1; ItemIndex := -1;
end; end;
@ -157,7 +157,7 @@ begin
if [csLoading, csDestroying] * ComponentState = [] then if [csLoading, csDestroying] * ComponentState = [] then
begin begin
FLookup.Initialize(FDataLink, Items); FLookup.Initialize(FDataLink, Items);
ItemIndex := FLookup.GetKeyIndex(FLookup.KeyFieldValue); ItemIndex := FLookup.GetKeyIndex;
end; end;
end; end;