3

I'd like to write a complex component that embeds other components. But I am not sure if I'll be able to connect to those components via object inspector.

To clarify, imagine a component that holds a list of TDataSources. These DataSource components are owned by this component and not visible on the form.

Now I'd like to connect a TDataset to one of these Datasources, is that possible, will these Datasources show up in the property editor combo of Dataset ?

1 Answers1

2

It is possible, but you have to type (or copy) the name; you cannot select it in the OI.

Using the component written below, you can type e.g. MyComp1.InternalDataSource into the DataSource property of a DBGrid:

uses
  Classes, DB;

type
  TMyComp = Class(TComponent)
  private
    FDataSource: TDataSource;
  public
    constructor Create(AOwner: TComponent);override;
  published
    property DataSource: TDataSource read FDataSource;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('TEST', [TMyComp]);
end;

{ TMyComp }

constructor TMyComp.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDataSource := TDataSource.Create(Self);
  FDataSource.Name := 'InternalDataSource';
end;
NGLN
  • 43,011
  • 8
  • 105
  • 200
bummi
  • 27,123
  • 14
  • 62
  • 101
  • That property setting will not be saved/streamed to the DFM, so you have to set it every time you open the form in the designer and you still need to set it at runtime. – NGLN Nov 13 '12 at 14:57
  • object DBEdit1: TDBEdit Left = 40 Top = 128 Width = 121 Height = 21 DataField = 'Name' DataSource = MyComp1.InternalDataSource TabOrder = 0 end will be stored , the assignment to a surfacedataset is just for testing, assumed to be part of the component. – bummi Nov 13 '12 at 15:06
  • Yes, this is more on topic, and a good example, sadly the ability to use ObjectInspector is crucial, so I'll have to figure out a different strategy, but I'll accept the answer anyway, as it answers the question in the title, and the answer is no (at least not via OI) –  Nov 15 '12 at 11:17