Subject | Re: [IBO] How to synchronize 3 grids (N-M relation) ? |
---|---|
Author | Helen Borrie (TeamIBO) |
Post date | 2002-02-25T12:05:17Z |
At 07:51 PM 22-02-02 +0000, you wrote:
DatasetA (master 1):
SELECT idA, desa FROM TABLA
Has DatasourceA.
DatasetB (master 2):
SELECT idB, desb FROM TABLB
Has DatasourceB.
DatasetC (detail):
SELECT idc, a, b from TLBC where a=:paramA and b=:paramB
Has DatasourceC.
Call a procedure in the AfterScroll events of both DatasetA and DatasetB:
procedure MyThing.DatasetAAfterScroll(IB_Dataset: TIB_Dataset);
begin
AfterMasterScroll(Self);
end;
...something like this:
procedure MyThing.DatasetBAfterScroll(IB_Dataset: TIB_Dataset);
begin
AfterMasterScroll(Self);
end;
procedure MyThing.AfterMasterScroll(Sender: TIB_Dataset);
var
MyParamName,
OtherParamName,
LinkParam: string;
begin
if Sender = DatasetA then
begin
MyParamName := 'ParamA' ;
OtherParamName := 'ParamB ;
LinkParam := 'idA;
if not DatasetB.Active then
DatasetB.Open;
end
else
begin
MyParamName := 'ParamB' ;
OtherParamName := 'ParamA' ;
LinkParam := 'idB';
if not DatasetA.Active then
DatasetA.Open;
end;
with DatasetC do
begin
DatasourceC.DisableInterface;
try
Close;
if Sender.Datasource <> MasterSource then
begin
MasterParamLinks.Clear;
MasterSource := nil;
if Sender = DatasetA then
MasterSource := DatasourceA
else
Master Source := DatasourceB;
MasterParamLinks.Add(MyParamName + '=' + Sender.Name + '.' +
LinkParamName) ;
end;
ParamByName(MyParamName).AsInteger :=
Sender.FieldByName(LinkParamName).AsInteger;
if Sender = DatasetA then
ParamByName(OtherParamName).AsInteger :=
DatasetB.FieldByName('idB').AsInteger
else
ParamByName(OtherParamName).AsInteger :=
DatasetA.FieldByName('idA').AsInteger;
finally
DatasourceC.EnableInterface;
end;
Open;
end;
end;
regards,
Helen Borrie (TeamIBO Support)
** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com
>Hello:OK, here's what I propose:
>
>How can I synchorize an N-M relation, in 3 grids?
>
>I explain:
>
>Suppose I have 3 tables:
>
>TBLA(#idA,desa)
>TBLB(#idB,desb);
>TBLC(#A,#B,#idC);
>
>
>I want to view the 3 queries in 3 grids, and when I moved into GRIDA,
>refresh GRIDC, and when I moved into GRIDB refresh GRIDC.
>
>The query TBLC is the next:
>
> select idc from TLBC where a=:idA and b=:idB
>
>It's similar like an detail with 2 masters.
>
>I can simulate the QUERY C, like an query with an MasterSource (for
>example A), and the other like an parameter, but it doesn't refresh
>good. Another solution for this problem?
DatasetA (master 1):
SELECT idA, desa FROM TABLA
Has DatasourceA.
DatasetB (master 2):
SELECT idB, desb FROM TABLB
Has DatasourceB.
DatasetC (detail):
SELECT idc, a, b from TLBC where a=:paramA and b=:paramB
Has DatasourceC.
Call a procedure in the AfterScroll events of both DatasetA and DatasetB:
procedure MyThing.DatasetAAfterScroll(IB_Dataset: TIB_Dataset);
begin
AfterMasterScroll(Self);
end;
...something like this:
procedure MyThing.DatasetBAfterScroll(IB_Dataset: TIB_Dataset);
begin
AfterMasterScroll(Self);
end;
procedure MyThing.AfterMasterScroll(Sender: TIB_Dataset);
var
MyParamName,
OtherParamName,
LinkParam: string;
begin
if Sender = DatasetA then
begin
MyParamName := 'ParamA' ;
OtherParamName := 'ParamB ;
LinkParam := 'idA;
if not DatasetB.Active then
DatasetB.Open;
end
else
begin
MyParamName := 'ParamB' ;
OtherParamName := 'ParamA' ;
LinkParam := 'idB';
if not DatasetA.Active then
DatasetA.Open;
end;
with DatasetC do
begin
DatasourceC.DisableInterface;
try
Close;
if Sender.Datasource <> MasterSource then
begin
MasterParamLinks.Clear;
MasterSource := nil;
if Sender = DatasetA then
MasterSource := DatasourceA
else
Master Source := DatasourceB;
MasterParamLinks.Add(MyParamName + '=' + Sender.Name + '.' +
LinkParamName) ;
end;
ParamByName(MyParamName).AsInteger :=
Sender.FieldByName(LinkParamName).AsInteger;
if Sender = DatasetA then
ParamByName(OtherParamName).AsInteger :=
DatasetB.FieldByName('idB').AsInteger
else
ParamByName(OtherParamName).AsInteger :=
DatasetA.FieldByName('idA').AsInteger;
finally
DatasourceC.EnableInterface;
end;
Open;
end;
end;
regards,
Helen Borrie (TeamIBO Support)
** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at
www.ibobjects.com