Meny
Index
  • Script
  • “OnManualBuild” page event
“OnManualBuild” page event
The FastReport core is usually responsible for report construction. It displays the report bands in a specific order, as many times as required by the data, thus creating a complete report. Sometimes it is necessary to display a report in a non-standard form which the FastReport core is unable to accomplish. In this case it is possible to construct a report manually using the “OnManualBuild” event of the report's design page. If the handler for this event is defined then the FastReport core transfers control to it when data output is required. At the same time the FastReport core automatically handles the display of those bands which are located on the page, such as “Report title”, “Page title”, “Column title”, “Report footer”, “Page footer”, “Column footer” and “Background”. The core also handles the creation of new pages and columns. The purpose of the “OnManualBuild” event handler is to display data bands, their titles and their footers in a user controlled order.
 
That is to say the essence of the “OnManualBuild” handler is to give commands to the FastReport core for displaying bands at particular times. The core does the rest itself : it creates new pages as soon as there is no free space on the current one, handles scripts attached to events, etc.
 
Let's demonstrate a handler using a simple example. This report has two master data bands which are not connected to data:
 
 
The handler will display these bands in alternate order (six times for each one). After six bands have been displayed a small gap will be inserted.
 
PascalScript:
 
procedure Page1OnManualBuild(Sender: TfrxComponent);
var
 i: Integer;
begin
for i := 1 to 6 do
begin
  { show two bands }
   Engine.ShowBand(MasterData1);
   Engine.ShowBand(MasterData2);
  { make a gap }
  if i = 3 then
     Engine.CurY := Engine.CurY + 10;
end;
end;
 
C++ Script:
 
void Page1OnManualBuild(TfrxComponent Sender)
{
int i;
 
for (i = 1; i <= 6; i++)
 {
  // show two bands
   Engine.ShowBand(MasterData1);
   Engine.ShowBand(MasterData2);
  // make a gap
  if (i == 3)
     Engine.CurY = Engine.CurY + 10;
 }
}
 
 
The following example displays the same bands, with a second copy shifted to the right.
 
PascalScript:
 
procedure Page1OnManualBuild(Sender: TfrxComponent);
var
 i, j: Integer;
 SaveY: Extended;
begin
 SaveY := Engine.CurY;
for j := 1 to 2 do
begin
  for i := 1 to 6 do
  begin
     Engine.ShowBand(MasterData1);
     Engine.ShowBand(MasterData2);
    if i = 3 then
       Engine.CurY := Engine.CurY + 10;
  end;
   Engine.CurY := SaveY;
   Engine.CurX := Engine.CurX + 200;
end;
end;
 
 
C++Script:
 
void Page1OnManualBuild(TfrxComponent Sender)
{
int i, j;
 Extended SaveY;
 
 SaveY = Engine.CurY;
for (j = 1; j <= 2; j++)
 {
  for (i = 1; i <= 6; i++)
   {
     Engine.ShowBand(MasterData1);
     Engine.ShowBand(MasterData2);
    if (i == 3)
       Engine.CurY = Engine.CurY + 10;
   }
   Engine.CurY = SaveY;
   Engine.CurX = Engine.CurX + 200;
 }
}
 
 
As you can see, in these examples we controlled only the output of data bands. The rest of the bands (in our case the “Report title”) were output automatically.
 
Finally we will show how to construct a report with a “List of clients” (we have shown several versions before) using the “OnManualBuild” event. This time connect the data band to the data source.
 
 
And use this script:
 
PascalScript:
 
procedure Page1OnManualBuild(Sender: TfrxComponent);
var
 DataSet: TfrxDataSet;
begin
 DataSet := MasterData1.DataSet;
 DataSet.First;
while not DataSet.Eof do
begin
   Engine.ShowBand(MasterData1);
   DataSet.Next;
end;
end;
 
C++Script:
 
void Page1OnManualBuild(TfrxComponent Sender)
{
 TfrxDataSet DataSet;
 
 DataSet = MasterData1.DataSet;
 DataSet.First();
while (!DataSet.Eof)
 {
   Engine.ShowBand(MasterData1);
   DataSet.Next();
 }
}
 
Preview the report to make sure that the script produces a report identical to the standard report. Note how we got a link to the Dataset - we connected a dataset variable to the data source using this code:
 
DataSet := MasterData1.DataSet;
 
If the MasterData band is not connected to a data source then the link to the required data source can be made in the following way:
 
DataSet := Report.GetDataSet('Customers');
 
Of course, the data source we are interested in must be enabled in the menu “Report > Data…” dialogue.
 
 
Onlinehjälpen skapades med Dr.Explain