Subject Re: [IBO] Changing MasterLinks at runtime
Author Geoff Worboys
> Well, I'm embarassed to say I don't know exactly how to change the
> MasterLinks through code. But I guess if I don't ask I'll never
> learn. Can you show me how?

There are various options, depending on how the link information is
stored and how many lines of link information you have.

Simple - one line of masterlinks:

IB_Query.MasterLinks.Text := 'ATABLE.AFIELD=BTABLE.BFIELD';
IB_Query.Open;

Still simple - two lines of master links:

IB_Query.MasterLinks.Text := 'ATABLE.AFIELD=BTABLE.BFIELD';
IB_Query.MasterLinks.Add( 'ATABLE.CFIELD=BTABLE.DFIELD' );
IB_Query.Open;
// the first line results in the table being closed and the
// existing links fully cleared and reset to the one line
// the second line simply adds the addition link info.
// there should not be any performance problems in this instance.

More complex but in some respects more direct:

var tmpStrs: TStringList;
begin
tmpStrs := TStringList.Create;
try
tmpStrs.Add( 'ATABLE.AFIELD=BTABLE.BFIELD' );
tmpStrs.Add( 'ATABLE.CFIELD=BTABLE.DFIELD' );
IB_Query.MasterLinks := tmpStrs;
if not IB_Query.Active then
IB_Query.Open;
finally
tmpStrs.Free;
end;

In this last option the masterlinks are set all in one call. I dont
think it matters in this situation because IBO does not try to reopen
the dataset after the SQL is changed in this way. However it is
probably more resilient code because it does not matter if IBO is
later changed to automatically reopen the dataset after masterlinks
are changed.

This last option is also how you would do it if you had the various
link lists stored in pre-existing stringlists elsewhere in the app.

Note that internally the masterlinks are a stringlist, IBO attaches an
OnChange handler to the stringlist to pickup changes however they are
assigned.


> Funny, IBObjects let's you do very complicated things without any
> code whatsoever.

One of my major works relies on exactly this feature. The forms are
stored in the database and work well just via property control. (I do
use my own derivations of IB_Query to support the specific
requirements of this app.)


hth

--
Geoff Worboys
Telesis Computing