Subject Re: [IBO] Datasource state aware button
Author Nando Dessena
Hi Marc,

> My Datasource is in the main datamodule and of course I could set a handler
> there and add chek to see if the main form is created and deal with it
> there, but I don't beleive this code belongs there

I agree absolutely. You definitely need an additional components, I was
just suggesting it be a DataSource. You can have two DataSource
components linked to the same dataset, one in the datamodule (if there's
the need) and one on the form. Personally, I often put datasource
components on the forms and only occasionally *also* in the datamodules
(depending on the role of the datasource objects: user interface or
dataset correlation).

> So in my main form I have the following (remember the mainform diaplay is
> read-only)
> procedure TfrmCDSMain.IB_DataSourceEvents1DataChange(Sender: TIB_DataLink;
> ADataSource: TIB_DataSource; AField: TIB_Column);
> begin
> inherited;
> if ( AField = nil ) then { browsing (should always be true in my case)}
> begin
> SetLinkedButtonState(ADataSource);
> end;
> end;

I still can't see the need for a DataSourceEvents proxy; all you need
here is a DataSource. It may be a case of personal preference, though.

> procedure TfrmCDSMain.PageControlLinksChange(Sender: TObject);
> begin
> inherited;
> with PageControlLinks do
> case ActivePage.Tag of
> 1 : IB_DataSourceEvents1.DataSource := DM.IB_DSRequest;
> 2 : IB_DataSourceEvents1.DataSource := nil;
> 3 : IB_DataSourceEvents1.DataSource := DM.IB_DSTask;
> 4 : IB_DataSourceEvents1.DataSource := nil;
> end;
> SetLinkedButtonState(IB_DataSourceEvents1.DataSource);
> SetLinkedButtonHints(IB_DataSourceEvents1.DataSource);
> end;

you may want to consider keeping one datasource and switch datasets to
reduce the need for additional code.