1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Dialog Components
  8. /
  9. DBLookup Extended Dialog ...

DBLookup Extended Dialog Control

The DB Lookup Extended control is a dataset-driven dropdown lookup field for use on report dialog pages. It wraps a grid control and provides incremental search, a multi-column dropdown grid, and full script access to the selected key value and display text.

It is well suited for letting users pick a customer, vendor, item, or any other entity from a list before the report runs โ€” returning the selected key value that can then be used to filter report data.


Adding to a Report

Drop a DB Lookup Extended onto a dialog page. Set the following properties in the Object Inspector to connect it to data:

  1. Set DataSetName to the name of the dataset that provides the lookup list
  2. Set KeyFieldNames to the field whose value will be returned as the selected key
  3. Set ListFieldNames to the field (or fields) displayed in the dropdown
  4. Optionally double-click the control to open the Column Editor and configure the dropdown grid columns

Column Editor

Double-clicking the control in the report designer opens the Lookup Column Editor, which lets you define the columns shown in the dropdown grid. Each column has three settings:

SettingDescription
Field NameThe dataset field to display in this column. If the dataset is open, a dropdown lists available fields.
CaptionThe column header text shown in the dropdown grid
WidthThe column width in pixels

Column definitions are stored internally as the ColumnDefs property in the format FieldName|Caption|Width separated by semicolons. For example:

CustNo|Customer No|100;CustName|Name|200;City|City|120

Properties

PropertyTypeDefaultDescription
DataSetNameStringName of the report dataset that provides the lookup list
KeyFieldNamesStringThe field name whose value is returned as the selected key. Can be a semicolon-delimited list for composite keys.
ListFieldNamesStringThe field name(s) shown in the edit portion of the control when a selection is made
ListFieldIndexInteger0Index of the field from ListFieldNames to display in the edit box
ColumnDefsStringColumn definitions for the dropdown grid. Set via the Column Editor or directly as a formatted string.
AutoOpenDataSetBooleanFalseWhen True, automatically opens the lookup dataset when the dialog page is activated if it is not already open
IncrementalFilteringBooleanTrueFilters the dropdown list as the user types
UseContainsOperatorBooleanFalseWhen True, incremental filtering matches anywhere in the string (contains). When False, matches from the start of the string (starts with).
HighlightSearchTextBooleanFalseHighlights matching text in the dropdown as the user types
DropDownRowsInteger8Number of rows visible in the dropdown grid before scrolling
DropDownWidthInteger0Width of the dropdown in pixels. 0 means match the control width.
DropDownHeightInteger0Height of the dropdown in pixels. 0 means automatic.
DropDownSizeableBooleanTrueAllows the user to resize the dropdown by dragging
DropDownAutoSizeBooleanFalseAutomatically sizes the dropdown to fit its content
GridModeBooleanFalseDisplays the dropdown as a full grid rather than a simple list
AutoSelectBooleanTrueAutomatically selects all text when the control receives focus
ImmediateDropDownBooleanFalseOpens the dropdown immediately when the control is activated
MaxLengthInteger0Maximum number of characters the user can type. 0 means unlimited.
HintStringTooltip text shown when the user hovers over the control
ShowHintBooleanFalseEnables display of the Hint tooltip

Runtime Properties

These properties are read-only at design time and are typically accessed from script during or after dialog interaction.

PropertyTypeDescription
KeyValueVariantThe key value of the currently selected record. Read or set this from script to get or pre-select a value.
TextStringThe display text currently shown in the edit portion of the control (read-only)

Events

EventDescription
OnChangeFires when the selected value changes. Use this to react to selection changes during the dialog โ€” for example to populate another control based on the selection.
OnClickFires when the control is clicked
OnDblClickFires when the control is double-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

Reading the selected key value in BeforeStartReport

After the user makes a selection in the dialog and clicks OK, read the KeyValue in BeforeStartReport to use it as a report parameter or dataset filter.

procedure BeforeStartReport;
begin
  // Pass the selected customer ID to a dataset parameter
  SetParam('qryOrders', 'CustomerID', DBLookupExtended1.KeyValue);
end;

Reading the display text

// Show the selected customer name in a report variable
Report.Variables['SelectedCustomer'] := DBLookupExtended1.Text;

Pre-selecting a value from script

// Pre-select a customer by key value when the dialog opens
DBLookupExtended1.KeyValue := 1001;

Reacting to selection changes with OnChange

Wire up the OnChange event to populate a second lookup based on the first selection. For example, selecting a customer could filter an orders lookup.

procedure DBLookupExtended1Change(Sender: TObject);
begin
  // Filter the orders dataset based on selected customer
  SetParam('qryCustomerOrders', 'CustomerID', DBLookupExtended1.KeyValue);
  qryCustomerOrders.Close;
  qryCustomerOrders.Open;
end;

Using the selected value in a SQL WHERE clause

procedure BeforeStartReport;
var
  custID: Variant;
begin
  custID := DBLookupExtended1.KeyValue;
  if not VarIsNull(custID) then
    SetParam('qryReport', 'CustomerID', custID)
  else
    RaiseException('Please select a customer before running this report.');
end;

Configuring ColumnDefs in script

Column definitions can also be set from script if needed, using the pipe-and-semicolon format.

// FieldName|Caption|Width separated by semicolons
DBLookupExtended1.ColumnDefs :=
  'CustNo|Customer No|80;CustName|Name|200;City|City|120';

Contains search vs starts-with search

// Allow matching anywhere in the field (e.g. typing 'smith' finds 'John Smith')
DBLookupExtended1.UseContainsOperator := True;
DBLookupExtended1.HighlightSearchText := True;