简体   繁体   English

LookupSource必须连接到TTable组件

[英]LookupSource must be connected to TTable component

I'm attempting to use a TDBLookupCombo, but am getting an error "EInvalidOperation with message 'LookupSource must be connected to TTable component'. 我正在尝试使用TDBLookupCombo,但收到错误消息“ EInvalidOperation,消息为“ LookupSource必须连接到TTable组件”。

I have the TDBLookupCombo.LookupSource connected to a TDataSource. 我将TDBLookupCombo.LookupSource连接到TDataSource。 The TDataSource.Dataset is pointing to a TClientDataSet which contains the records for the lookup table (Fields ID and Description). TDataSource.Dataset指向一个TClientDataSet,其中包含查找表的记录(字段ID和描述)。

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

Is this not possible to do since TCilentDataSet isn't a descendant of TTable? 因为TCilentDataSet不是TTable的后代,所以这不可能吗? If so then what would be the best alternative without using 3rd party components. 如果是这样,那么在不使用第三方组件的情况下最好的选择是什么。

TDBLookupCombo is one of the old BDE-based data controls, which is why it's dependent on connecting to a TTable . TDBLookupCombo是基于BDE的旧数据控件之一,这就是为什么它依赖于连接到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 ). 看来您应该改用TDBLookupComboBox ,它可以很好地连接到TDataSource ,后者连接到任何双向TDataSet后代(包括TClientDataSet )。

Looking at the code...Nope you can't do that, descends to TDataSet...TClientDataSet -> TCustomClientDataSet -> TDataSet 查看代码...不,您不能那样做,下降到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 嗯...免费...检查Jedi组件...也许TJvDBLookupComboEdit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM