1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Dialog Components
  8. /
  9. Connection Switcher Dialo...

Connection Switcher Dialog Control

The Connection Switcher control allows users to reassign database connections within a report dialog at runtime. It displays a grid listing every TfrxFDDatabase component in the report, showing its current connection and allowing the user to select a different one from a dropdown of all available connection definitions.

Connection assignments are automatically saved to an INI file in the Articles settings folder and reloaded the next time the same report is run, so users only need to configure connections once per report.

When the Hide property is set to True, the control applies saved connection mappings silently with no UI โ€” useful for automated or scheduled reports.


DataSoft's Articles Connection Switcher Dialog Control

Adding to a Report

Drop a Connection Switcher onto a dialog page in the report designer. It will automatically discover all TfrxFDDatabase components in the report โ€” no additional configuration is needed to populate the grid.

Size the control to fit your dialog. A minimum height of around 160 pixels is recommended to show several rows comfortably.


How It Works

When the report runs, the Connection Switcher reads the saved INI file for that report and pre-fills the New ConnectionDef column with any previously saved choices. The grid shows four columns:

ColumnDescription
ComponentThe name of the TfrxFDDatabase component in the report
CurrentThe connection definition currently assigned to that component
DescriptionThe human-readable description from the database component
New ConnectionDefEditable dropdown โ€” select the connection to use for this run

When the user changes a value in the New ConnectionDef column, the change is applied immediately to the live database component and saved to the INI file. No OK button is needed โ€” changes take effect as soon as they are selected.

The INI file is stored in the Articles settings folder as <ReportName>connect.ini.


Properties

PropertyTypeDefaultDescription
HideBooleanFalseWhen True, the control is invisible and applies saved mappings silently without showing any UI. Use this for automated or scheduled reports where connection selection should happen without user interaction.

Script Methods

The following methods are available in the report script.

MethodDescription
ApplyMappingsApplies the current grid selections to all TfrxFDDatabase components in the report. Called automatically when a selection changes, but can also be called manually from script.
SaveMappingsSaves the current grid selections to the INI file. Called automatically on change.
LoadMappingsReloads saved selections from the INI file and applies them to the grid.

Events

EventDescription
OnClickFires when the control is clicked
OnEnterFires when focus enters the control
OnExitFires when focus leaves the control
OnKeyDownFires when a key is pressed down
OnKeyPressFires when a key is pressed
OnKeyUpFires when a key is released
OnMouseDownFires when a mouse button is pressed
OnMouseMoveFires when the mouse moves over the control
OnMouseUpFires when a mouse button is released

Examples

Basic use โ€” visible connection picker

Drop the control onto a dialog page and leave Hide = False. The user sees the grid and can change connections before the report runs. No script is required for basic use.

Silent mode โ€” apply saved connections automatically

Set Hide = True in the Object Inspector. The control will silently load and apply whatever connections were last saved for this report, with no dialog shown to the user.

// You can also toggle Hide from script if needed
ConnectionSwitcher1.Hide := True;
ConnectionSwitcher1.ApplyMappings;

Resetting connections from script

// Force a reload from the saved INI file and re-apply
ConnectionSwitcher1.LoadMappings;
ConnectionSwitcher1.ApplyMappings;

Manually applying after a script change

// If you programmatically change something and need to push it through
ConnectionSwitcher1.ApplyMappings;
ConnectionSwitcher1.SaveMappings;

Typical dialog page setup

A common pattern is to place the Connection Switcher on its own dialog page, or combine it with other parameter controls. The report then uses whichever connection the user selected when the dialog was submitted.

// In BeforeStartReport โ€” no action needed, the control handles everything.
// Connections are already switched by the time BeforeStartReport runs.

// To verify which connection is active for a given database component:
ShowMessage(frxFDDatabase1.ConnectionDefName);

INI File Location

Saved connection mappings are stored at:

<SettingsFolder>\<ReportName>connect.ini

Where <ReportName> is derived from the report’s ReportOptions.Name property with the category prefix removed and any characters that are invalid in filenames stripped. You can find the settings folder path using the GetSettingsFolder system function.

To reset the saved connections for a report, simply delete the corresponding connect.ini file from the settings folder.