mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 03:16:10 +02:00
lcl: simplified TDBLookup.UpdateData;
remove TDBLookup.FLookupList. Not needed anymore handle setting Null data git-svn-id: trunk@34084 -
This commit is contained in:
parent
3b2f0d4e32
commit
372a68c92c
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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 := '';
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user