I am trying to create a bidirectional report that expands both horizontally and vertically. On both axes, there are an unknown number of rows/columns. I have been trying to use TLists and a hierarchical class system. Is it possible to use the addtable method to add the data set for each date along the horizontal? See code below. I am on Delphi Tokyo 10.2. Thanks.
Hi, Doing a report with the nesting in this way is not possible as
far as I can see it, because you have 2 independent ranges (the times
and the dates), but in the data model times are inside the dates.
There
should be possible to do something by using the nested names: that is
instead of <#MondayDates.MondayTime> you should use
<#MondayDates.MondayDataset> since that is the field that
MondayDates exposes. But I don't think it makes much sense to try to
make this model hierarchically at all: For this case a relational model
(which FlexCel also handles) comes much more naturally.
So what I would do is to have 3 datasets: MondayDates: TObjectList<TMondayDate>; MondayTimes: TObjectList<TMondayTime>; MondayData: TObjectList<TMondayData>;
(side note: I used TObjectList instead of TList so the classes inside the list are freed when you free the list).
Where: TMondayDate = class public Date: String; constructor Create(const aDate: string); end;
TMondayTime = class public Time: String; constructor Create(const aTime: string); end;
TMondayData = class public Data: String; Date: string; Time: string; constructor Create(const aDate, aTime, aData: string); end;
And then add the relationships: Report.AddRelationship('MondayTimes', 'MondayData', 'Time', 'Time'); Report.AddRelationship('MondayDates', 'MondayData', 'Date', 'Date');
You might even use a single dataset and use Distinct to get the Dates and Times datasets. Once you have the 3 datasets related, the template is just writing the 3 ranges. I attach an example here: http://www.tmssoftware.biz/flexcel/samples/bidilist.zip
But
to do it like in this second case you would define only the "Dates" and
"Times" datasets, then use an user defined function that takes a date
and a time and returns a data. The template would be like this:
And you would add an user defined function GetData that returns the data for a time and a date. In
this case you wouldn't need to add relationships, but I think using an
user defined function for this might be a little overkill.