TDataSource 后代作为子组件的无效属性路径错误

发布于 2024-11-30 20:35:30 字数 964 浏览 3 评论 0 原文

我正在尝试设计一组包含自己的数据库访问的数据控件。 因此,我创建了一个 TDataSource 后代,它具有附加属性,可以将其自身附加到数据库并创建数据集等...

如果我将其附加到 DBLookupComboBox 作为 ListSource 一切都很好。但是,如果我尝试创建此数据源作为 DBLookupComboBox 的子组件并将其指定为 ListSource,我会达到似乎 第 22 条军规

我希望 DataSource 的属性与 DBLookupComboBox 一起进行流式传输,并且希望将 DBLookupComboBox 的 ListSource 设置为 DataSource 子组件,但我似乎无法同时执行这两个操作。当 DBLookupComboBox 进行流式传输时,DataSource 的附加属性将被包含两次,一次(正确地)在 DataSource 属性本身下,一次在 ListSource.Property1 下,最后一次将导致“无效的属性路径” > 当组件加载时,即使数据源是预先创建的(并注册等)。

如果 TDataSource 是子组件,只要它设置了一些非默认属性(即标签),也会发生同样的情况。

我尝试设计一个存储函数,允许 DataSource 属性进行流式传输,但不允许 ListSource 属性进行流式传输,但没有成功。

对于如何开展这项工作的任何帮助或指导,我将不胜感激。

DFM(片段)看起来像

object PmDCB1: TPmDCB
  Left = 384
  Top = 160
  Width = 145
  Height = 24
  ListSource.Tag = 222
  TabOrder = 0
  ViewName = 'VAR'
  WindowName = 'WNE'
  View.Tag = 222
end

I am trying to design a set of data controls that contain their own database access.
So I create a TDataSource descendant which has additional properties and can attach itself to the database and create datasets etc...

If I attach this to a DBLookupComboBox as the ListSource all is well. However if I try to create this Datasource as a subcomponent of the DBLookupComboBox and specify it as the ListSource, I reach what seems a catch-22.

I wish the properties of the DataSource to be streamed with the DBLookupComboBox, and I wish the ListSource of the DBLookupComboBox to be set to the DataSource subcomponent but I cannot seem do both. When the DBLookupComboBox is streamed, the additional properties of the DataSource will be included twice, once (correctly) under the DataSource property itself, and once under ListSource.Property1 and this last will cause an “Invalid property path” when the component is loaded, even if the DataSource is created up front (and registered etc).

The same thing happens if a TDataSource is the subcomponent as long as it has some non default property (ie Tag) set.

I have tried to devise a Stored Function that would allow the DataSource properties to stream but not the ListSource properties without success.

I would be grateful for any help or direction on how to make this work.

The DFM (fragment) looks like

object PmDCB1: TPmDCB
  Left = 384
  Top = 160
  Width = 145
  Height = 24
  ListSource.Tag = 222
  TabOrder = 0
  ViewName = 'VAR'
  WindowName = 'WNE'
  View.Tag = 222
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

貪欢 2024-12-07 20:35:30

好的 - 最终找到了一个有效的答案 - 覆盖 DBLookupComboBox 的 WriteState 过程并将 ListSource 设置为 nil,然后调用继承,然后再次设置 ListSource。
不太难看,这是我能找到的唯一能在一周的挖掘中起作用的东西。

OK - eventually found an answer that works - Override the DBLookupComboBox's WriteState procedure and set the ListSource to nil, then call inherited, then set ListSource back again.
Not too ugly and its the only thing i could find that works in a week of digging.

逆蝶 2024-12-07 20:35:30

您是否尝试过类似以下的操作?

type
  TMyDBLookupComboBox = class(TDBLookupComboBox)
  private
    FListSource: TMyDataSource;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation);
      override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property ListSource: TMyDataSource read FListSource;
  end;

constructor TMyDBLookupComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FListSource := TMyDataSource.Create(Self);
  FListSource.SetSubComponent(True);
  FListSource.Name := 'ListSource';
  FListSource.FreeNotification(Self);
  inherited ListSource := FListSource;
end;

procedure TMyDBLookupComboBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (AComponent = FListSource) then
  begin
    FListSource := nil;
    inherited ListSource := nil;
  end;
end;

Have you tried something like the following?

type
  TMyDBLookupComboBox = class(TDBLookupComboBox)
  private
    FListSource: TMyDataSource;
  protected
    procedure Notification(AComponent: TComponent; Operation: TOperation);
      override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property ListSource: TMyDataSource read FListSource;
  end;

constructor TMyDBLookupComboBox.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FListSource := TMyDataSource.Create(Self);
  FListSource.SetSubComponent(True);
  FListSource.Name := 'ListSource';
  FListSource.FreeNotification(Self);
  inherited ListSource := FListSource;
end;

procedure TMyDBLookupComboBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (AComponent = FListSource) then
  begin
    FListSource := nil;
    inherited ListSource := nil;
  end;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文