In our Delphi 2007 application we use many of the following constructs
FdmBasic:=TdmBasicData(FindOwnerClass(AOwner,TdmBasicData));
FindOwnerClass moves the owner hierarchy of the current component up to find a specific class (in the TdmBasicData example). The resulting object is stored in the FdmBasic field variable. We use this primarily for transmitting datamodules.
Example: When generating a report, the resulting data is compressed and stored in the Blob field of the table, accessible through the datamodule TdmReportBaseData. In a separate module of our application, there is a function that displays data from a report in Paged form using ReportBuilder. The main code of this module (TdmRBReport) uses the TRBTempdatabase class to convert compressed blob data into different tables that can be used in the Reportbuilder runtime report scheduler. TdmRBReport has access to TdmReportBaseData for all types of data related to the report (report type, report calculation settings, etc.). TRBTempDatabase is created in TdmRBReport, but has access to TdmReportBasedata. So now this is done using the construct above:
constructor TRBTempDatabase.Create(aOwner: TComponent); begin inherited Create(aOwner); FdmReportBaseData := TdmRBReport(FindOwnerClass(Owner, TdmRBReport)).dmReportBaseData; end;{- .Create }
I feel this means that TRBTempDatabase knows a lot of its owner, and I was wondering if this is some kind of code smell or Anti-pattern.
What do you think about it? Is that the smell of code? If so, which way is better?
source share