Почему не работает без задания LookupSource?
В TDBLookupComboBox если DataField := DataSet.LookupField то LookupSource создается автоматически:
procedure TDBLookup.DoInitialize;
var
ListFields: TList;
ListLinkDataset: TDataSet;
begin
FDataFields.Clear;
FKeyFields.Clear;
FListField := nil;
FHasLookUpField := False;
FLookUpFieldIsCached := False;
if Assigned(FControlLink) and Assigned(FControlLink.DataSet)
and FControlLink.DataSet.Active then
begin
if Assigned(FControlLink.Field) then
begin
FHasLookUpField := (FControlLink.Field.FieldKind = fkLookup);
FLookUpFieldIsCached := (FHasLookupField and FControlLink.Field.LookupCache);
if FHasLookUpField then
begin
if FLookupSource = nil then
FLookupSource := TDataSource.Create(Self);
if (FLookupSource.DataSet <> FControlLink.Field.LookupDataSet) then
FLookupSource.DataSet:= FControlLink.Field.LookupDataSet;
FListLink.DataSource := FLookupSource;
FDataFieldNames := FControlLink.Field.KeyFields;
FKeyFieldNames := FControlLink.Field.LookupKeyFields;
end else
FDataFieldNames := FControlLink.Field.FieldName;
FControlLink.DataSet.GetFieldList(FDataFields, FDataFieldNames);
end;
end;
if not FHasLookUpField then
FListLink.DataSource := FListSource;
if (FKeyFieldNames > '') and FListLink.Active then
begin
ListLinkDataset := FListLink.DataSet;
ListFields := TList.Create;
try
ListLinkDataset.GetFieldList(ListFields, FListFieldName);
ListLinkDataset.GetFieldList(FKeyFields, FKeyFieldNames);
if FHasLookUpField then
begin
FListField := ListLinkDataset.FindField(FControlLink.Field.LookupResultField);
if (Assigned(FListField) and (ListFields.IndexOf(FListField) < 0)) then
ListFields.Insert(0, FListField);
if (ListFields.Count > 0) then
FListField := TField(ListFields[0]);
end else
begin
if ((FKeyFields.Count > 0) and (ListFields.Count = 0)) then
ListFields.Add(FKeyFields[0]);
if ((FListFieldIndex > -1) and (FListFieldIndex < ListFields.Count)) then
FListField := TField(ListFields[FListFieldIndex])
else
FListField := TField(ListFields[0]);
end;
finally
ListFields.Free;
end;
FetchLookupData;
end;
end;