Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Link datables

edited October 2001 in General
Hi,

I have created report and designer by code, I have also added my Dataviews
and joined table by code, so I can create report by code and prepare it for
the user with the main tables. But it remains one (I hope :-) problem : I
have created a procedure to link 2 tables by code (for master / detail) but
it doesnt work properly.

After creating my link by code, when I open the designer or the dataManager
the tables dont appear in master detail position. Meanwhile, when I open the
link dialog on the detail dataview in the datamanager, the link appear
correctly (field X -> Field Y) but I dont see the colored line between the
dataviews.

I have added my procedure, it's simple : I search the necessary dataviews
and Fields and call daSQL.CreateLink. I suppose that I must call an other
procedure after this last, but I dont know which.

Please help :-)

Thanks

Davy Anest
EBP Informatique

procedure LinkTables(ATableName1, ATableName2, AFieldName1,
AFieldName2: String);
var
lDataModule: TdaDataModule;
lDataView1, lDataView2: TdaADOQueryDataView;
Field1, Field2: TdaField;
intI: Integer;
begin
lDataView1 := nil;
lDataView2 := nil;
Field1 := nil;
Field2 := nil;
// datamodule
lDataModule := daGetDataModule(FPrinter.FReport);
// recherche les tables
for intI := 0 to lDataModule.DataViewCount - 1 do
if
SameText(TdaADOQueryDataView(lDataModule.DataViews[intI]).Sql.SelectTables[0
].TableName,
ATableName1) then
lDataView1 := TdaADOQueryDataView(lDataModule.DataViews[intI])
else if
SameText(TdaADOQueryDataView(lDataModule.DataViews[intI]).Sql.SelectTables[0
].TableName,
ATableName2) then
lDataView2 := TdaADOQueryDataView(lDataModule.DataViews[intI]);
// si on a trouv? les tables
if Assigned(lDataView1) and Assigned(lDataView2) then
begin
lDataView2.SQL.SkipWhenNoRecords := False;
lDataView2.SQL.MasterSQL := lDataView1.SQL;
// on recherche les champs
for intI := 0 to lDataView1.SQL.SelectFieldCount - 1 do
if SameText(lDataView1.SQL.SelectFields[intI].FieldName, AFieldName1)
then
begin
Field1 := lDataView1.SQL.SelectFields[intI];
Break;
end;
for intI := 0 to lDataView2.SQL.SelectFieldCount - 1 do
if SameText(lDataView2.SQL.SelectFields[intI].FieldName, AFieldName2)
then
begin
Field2 := lDataView2.SQL.SelectFields[intI];
Break;
end;
// si on a trouv? les champs
if Assigned(Field1) and Assigned(Field2) then
lDataView2.SQL.CreateLink(Field1, Field2);
end;
end;

Comments

  • edited October 2001
    Hi Davy,

    I am not sure that's the best way but it seems to work.

    -------
    procedure LinkTables(AReport: TppCustomReport;
    AMasterTable, ADetailTable, AMasterField, ADetailField: string);
    var
    lDataModule: TdaDataModule;
    lDataViewM, lDataViewD: TdaQueryDataView;
    function DataViewByTableName(ADataModule: TdaDataModule;
    ATableName: string): TdaQueryDataView;
    var
    I, J: integer;
    begin
    for I := 0 to ADataModule.DataViewCount - 1 do
    begin
    Result := TdaQueryDataView(lDataModule.DataViews[I]);
    for J := 0 to Result.SQL.SelectTableCount - 1 do
    if SameText(Result.SQL.SelectTables[J].TableName, ATableName) then
    Exit;
    end;
    Result := nil;
    end;
    begin
    lDataModule := daGetDataModule(AReport);
    lDataViewM := DataViewByTableName(lDataModule, AMasterTable);
    lDataViewD := DataViewByTableName(lDataModule, ADetailTable);
    if Assigned(lDataViewM) and Assigned(lDataViewD) then
    begin
    lDataViewD.CreateLink(lDataViewM, AMasterField, ADetailField);
    lDataViewD.UpdateLinkColors(True);
    if (lDataViewD.DataPipelineCount > 0) and
    (lDataViewM.DataPipelineCount > 0) then
    lDataViewD.DataPipelines[0].MasterDataPipeline :=
    lDataViewM.DataPipelines[0];
    lDataModule.Modified := True;
    end;
    end;

    -------

    I hope that Nard will correct me if I am wrong.

    --

    Alex - SoWily
    alex@sowily.com
    www.sowily.com


This discussion has been closed.