Example: Abort Report Building
- 2 minutes to read
This example demonstrates how to cancel the building of a report in response to an action by an end-user (pressing the Esc key). There is a form containing the TdxComponentPrinter component and a button. Clicking the button invokes the preview window for the report link associated with the component printer.
The code below demonstrates how to abort the building of a report when the Esc key is pressed:
// Define the AAbortBuilding variable used as a flag indicating if
...
var
Form1: TForm1;
AAbortBuilding: Boolean;
implementation
...
property to let the form receive keyboard
// variable, invoke the preview window and then restore the form's
procedure TForm1.Button4Click(Sender: TObject);
begin
KeyPreview := True;
AAbortBuilding := False;
dxComponentPrinter1Link1.Preview(False);
KeyPreview := False;
end;
// Handle the form's OnKeyDown event and set the flag according to the
// key pressed.
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
AAbortBuilding := (Key = vk_Escape);
end;
// Once the flag variable is changed, set the report link's
// AbortBuilding property to True to indicate that the building of
// the report should be stopped and show an appropriate message.
procedure TForm1.dxComponentPrinter1GenerateReportProgress(Sender: TObject; AReportLink: TBasedxReportLink; APercentDone: Double);
begin
if AAbortBuilding then
begin
AReportLink.AbortBuilding := AAbortBuilding;
'Message'
end;
end;
See Also