You can prompt for custom report options or parameters in the setup form by laying out any suitable components in a TGroupBox container on the form, and passing that group box to the setup form.

It's that easy.


Consider a report requiring a date range and a minimum value parameter. You could create a group box (MyReportGroupBox) looking like this:

 

Setup report options

 

If the parent form of MyReportGroupBox will be visible, you can hide MyReportGroupBox (set Visible := False) so that it does not interfere with the form display. Otherwise, any event code can be assigned to the report option components to help the user set them. Access data, provide shortcuts, set bindings, or whatever you need...

Finally, simply assign the groupbox to property ReportWriter.ReportOptionGroupBox (in ReportWriter.OnConfigure) to make it available in the report setup form:

procedure TForm1.ReportWriter1Configure(ReportInterface: TReportInterface; ReportWriter: TReportWriter);

begin

with ReportWriter do

begin

ReportOptionGroupBox := MyReportGroupBox;

end;

end;

 

When the report is executed, the setup form will look something like this:

 

Setup report options

 

Internally, when the setup form instance is created for the report, it will temporarily parent the groupbox, make it visible, and, within reasonable limits, adjust its own size to accommodate the size of the groupbox. This means the components you created on your form are transferred to and displayed on the setup form, and any associated code is operational in the context of the setup form.

See the next example to find out how you can initialise and validate the users setup options.