1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Articles Report Designer ...
  8. /
  9. Dialog Events and Scripti...

Dialog Events and Scripting

Available Dialog Events

DialogPage Events:

  • OnShow – When dialog is displayed
  • OnCloseQuery – Before dialog closes (can cancel)
  • OnClose – After dialog closes
  • OnActivate – When dialog becomes active

Control Events:

  • OnChange – Value changed (Edit, ComboBox)
  • OnClick – Button clicked
  • OnEnter – Control gains focus
  • OnExit – Control loses focus

Event Scripting Basics

All dialog scripts use PascalScript (a Pascal subset).

Accessing the script editor:

  1. Select the dialog page or control
  2. Click the Events tab in the Object Inspector
  3. Double-click an event to create the handler

Common Scripting Patterns

Validate input before closing:

pascal

procedure DialogPage1OnCloseQuery(Sender: TfrxComponent; var CanClose: Boolean);
begin
  // Check if required fields are filled
  if VarIsNull(DBLookupComboBox1.KeyValue) then
  begin
    ShowMessage('Please select a customer');
    CanClose := False;
    Exit;
  end;
  
  if DateEdit1.Date > DateEdit2.Date then
  begin
    ShowMessage('Start date must be before end date');
    CanClose := False;
    Exit;
  end;
  
  // All validation passed - set query parameters
  qryOrders.Close;
  qryOrders.ParamByName('CustomerID').Value := DBLookupComboBox1.KeyValue;
  qryOrders.ParamByName('StartDate').Value := DateEdit1.Date;
  qryOrders.ParamByName('EndDate').Value := DateEdit2.Date;
  qryOrders.Open;
  
  CanClose := True;
end;

Cascade ComboBoxes (change one updates another):

pascal

procedure ComboBoxRegionOnChange(Sender: TfrxComponent);
begin
  // When region changes, update cities list
  qryCities.Close;
  qryCities.ParamByName('RegionID').Value := ComboBoxRegion.KeyValue;
  qryCities.Open;
  
  // Reset city selection
  DBLookupComboBoxCity.KeyValue := Null;
end;

Set defaults on show:

pascal

procedure DialogPage1OnShow(Sender: TfrxComponent);
begin
  // Set date range to last 30 days
  DateEdit2.Date := Date;  // Today
  DateEdit1.Date := Date - 30;  // 30 days ago
  
  // Set combo to first item
  if ComboBox1.Items.Count > 0 then
    ComboBox1.ItemIndex := 0;
    
  // Set lookup to first customer
  var ds := DBLookupComboBox1.ListSource.DataSet;
  if Assigned(ds) and (ds.RecordCount > 0) then
  begin
    ds.First;
    DBLookupComboBox1.KeyValue := ds.Value['CustomerID'];
  end;
end;