开发者

Invalid property path error for a TDataSource descendant as a SubComponent

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 ListSourc开发者_运维问答e 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


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.


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜