Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to connect a property to an embedded component

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 Answers

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;
like image 72
bummi Avatar answered Nov 23 '25 02:11

bummi