LookupSource must be connected to TTable component

930 views Asked by At

I'm attempting to use a TDBLookupCombo, but am getting an error "EInvalidOperation with message 'LookupSource must be connected to TTable component'.

I have the TDBLookupCombo.LookupSource connected to a TDataSource. The TDataSource.Dataset is pointing to a TClientDataSet which contains the records for the lookup table (Fields ID and Description).

LookupDisplay := 'Description';
LookupField := 'ID';
LookupSource := dsLookup;

Is this not possible to do since TCilentDataSet isn't a descendant of TTable? If so then what would be the best alternative without using 3rd party components.

2

There are 2 answers

0
Ken White On BEST ANSWER

TDBLookupCombo is one of the old BDE-based data controls, which is why it's dependent on connecting to a TTable.

It seems you should be using TDBLookupComboBox instead, which works fine connected to a TDataSource which is attached to any bi-directional TDataSet descendant (which includes TClientDataSet).

3
House of Dexter On

Looking at the code...Nope you can't do that, descends to TDataSet...TClientDataSet -> TCustomClientDataSet -> TDataSet

procedure TDBLookupList.SetLookupSource(Value: TDataSource);
begin
  if (Value <> nil) and ((Value = DataSource) or
    ((Value.DataSet <> nil) and (Value.DataSet = FFieldLink.DataSet))) then
    raise EInvalidOperation.Create(SLookupSourceError);
  if (Value <> nil) and (Value.DataSet <> nil) and
    not (Value.DataSet.InheritsFrom(TTable)) then
    raise EInvalidOperation.Create(SLookupTableError);
  inherited DataSource := Value;
  NewLayout;
end;

hmmm...Free...check out Jedi components...maybe TJvDBLookupComboEdit