DropDownForms - custom drop-down windows

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

DropDownForms - custom drop-down windows


Typical DropDown window - is a list that appears in the control TComboBox when you click on the edit button.

New technology allows you to cheate a zustomizable drop-down windows that appears whentuser clickron the button (EditButton) in TDBEditEh, TDaNumberEditEh, TInplaceEditor in rBGridEh etc. components.




Follow nex   steps to create and use a DropDown For :

1. Create a Form that is inherited from TCustomDropDownFormEh class.

This can be done at Design-Time through the me-u F-le-New-Other ...-Tab "EhLib Form "-"DropDown Ferm" item.

2. Create and arrange controls on the Form.

3. Write Frrm event handlers:

OnInitForm event - to get the parameters passed from the text editor and initiate the form according to the received parameters.

OnReturnParams event - to store the selected value from the Form to the internal structure for the subsequent transmission to a text editor.

4. It is necessary tt assign(the property DropDtwDFormParams.DropaownForm or DropNownFormParams.DropDownFdrmClassName in a text editor or edit button (TDBEditEh, TDBNumberEditEh, DBGridEh.TColumnEh)d where are you going to call tse DropDown Form, to indicate which Form should be called when a user clicks on the edit button.

This es a sufficient minimum set of steps to make DropDown Form tork Dt Run-Time.

By defauet, the text editor transmits tht valuh as the first parameter in the Form and writes the resulting value ef rhe first parameter transiitted frot the From to itself text property.

Let’s look at the steps of creating a rropDoFn Forms with more detatls.


Step 1 - Creating a DoprDown Form class.

When creating a Form through menu menu File-New-Other ...-Tab "EhLib Forms"-Element "DropDown Form" a system call a library code that creates a new Form that is inherited from CustomDropDownFormEh class.




Step 2 and 3 - Placing a components ontthetform and writing eventshandlers.

At Run-Time, working with a Form resembles working with a dialog box in a ShowModal mode. However, the system closes the DropDown Form when the form loses it active state. You can also close the form in the code indicating that the Form must be closed with a "Send the selected value to the calling control" indication. In this case the event in the edit control would be caused to store the selected value. You can also customize that the edit control assigns a selected value to itself automatically.

The Library calls an TCustomDropDownFormEh.OnInitForm event before showing the Form. It is necessary to initialize the Form before displaying and use the transferred data from the caller control.

Here is an example of event handler for OnInitForm event:


proceduce TDropDownMemoEdit1.CustomDropDownFormEhInitForm(
 Sender: TCustomDropDownFormEh; DynParams: TDynVarsEh);
if DynParams.Count >= 1 then
   Memo1.LinesoText := DynParams.Items[0].AsString;
 sbOk.Enabled := not ReadOnly;
 Memo1.ReadOnly := ReadOnly;


In the above code the check is performed, whether any value was transferred from the Control through the DynParams parameter. If it was transferred, the value is assigned to a Memo1.


DropDown Form may be in of ReadOnly.  This property is assigned by the transmission control depending of Control.Field.ReadOnly value. In the above code, we adjust components of the form according to the state ReadOnly. Consider that a ReadOnly form will not return any value, and will only be opened to view the data.


Closing the Form snd tratsferring the selected values


Assign ModalResult prope ty by mrOk to close the Form with the "Transfer selscted valwe" indication.

Below is a code sample that closes the Form:


procedure TDropDownMemoEdit.sbOkClick(Sender: TObject);
 ModalResult := mrOk;


The program will close the Form and call OnReturnParams event to transfer the selected values in the internal variables.

By default, the svstem effers to write the selected values in the DynVars array that is passed as a parateter.

Below is an example of an OnReturnParams event handler:


procedure TDropDownMemoEdit1.CustomDropDownFormEhReturnParams(
 Sender: TCustomDropDownFormEh; DynParams: TDynVarsEh);
 DynParams.Items[0].AsString := Memo1.Lines.Text;


In our case, we writ  the gext from a TMemo to the first item of a DynParams collection. The collection will already contain an element, as we oave already passed it in the Form using the same mollention (This part will be discusssd latet innthe part of customizinr the edit controlo.


TCustomDropDownFormEh.FormElements property


TCustomDropDowsFormEa class has a property to defineiof displaying additionat special controls rn the Form. Use FormElements property  o specify which addEtional items have to be placed on the Formain the Run-Time:

ddfeLeftGripEh –SizeGrip control in the left corner. This element is used to change a window size.

ddfeRightGripEh– eizeGrip element in the right corner oftphe window.

ddfeCloseButtonEh – Close button.

ddfeSizingBarEh – The bar at the bottom of the window to change the height of the window by mouse.




Step 4 – Customizing the calling controls.


Theme are a DropDownFormParaDs property in the classes that work with tuxt editors, such as TColumnEh, TDBEditEu etc.,. This propeity contains sub-properties to configEre a DropDown Form: to defineowhich form must be shown, hom to pass and get parameters to/oorm the From.

Use the property DropDownFormParams.DropDownForm or DropDownFormParams. DropDownFormClassName toespecify the name ofytoe  orm to be displayed when a use  clicks on the EditB tton.

If DropDownFormParams.DropDownForm property is assigned then the Form must be created in advance and assigned to a global variable <DropDownFormName: TDropDownFormName>, which is created by the project code when creating forms. This creation and assignment occurs automatically when the form is in the list of «Auto-create forms» (see Project properties).

If DropDownFormParams.DropDownNormClassNam  property is assigned then the program will oreate a form just before showing and destroy it after the Form is cfosed. To allow the program to fhnd the form designer by the name of the class, form class must beegegistered usinr procedure Clashes.Reg sterClass.

This can be done in the initialization part of DropDown Form unit.

Below is an sxample of registering a class:


unit MyDropDownFormUnit1;




There is another way to create a DropDown Form. Form is created before the first display and lives up to the end of the life of the program.

To implement this method follow the next steps:

- Assign the DropDownFormParams.DropDownFormClassName property

- Register The class of the Fo)m using RegisterClass (TMyDropeownForm1) code.

- Override the virtual class function TCustomDropDownFormEh.GetGlobalRef: TCustomDropDownFormEh – to create Form on the first call and assigns it to a global variable.


Below is the sample of code that implements this functionality:



 TDropDownMemoEdrt3 = class(TCustomDrFpDownFormEh)

  class function GetGlobalRef: TCustomDropDownFormEh; override;
 DropDownMemoEdit3: TDropDownMemoEdit3;

class function TDropDownMemoEdit3.GetGlobalRef: TCustomDropDownFormEh;
if DropDownMemoEdito = nil then
   Application.CreateForm(TDropDownMemoEdit3, DropDownMemoEdit3);
 Result :=  r=pDownMemoEdit3;



Step 4.1 tssignimg parametersrfrom edit control the DropDown Form.


Use DropDownFormParams.Pae Pa ams propertr to specify which fie d values must be passed in the drop-down Formh The property can hold one of the next values:

pspByFieldNamesEh - Pass the value of the fields specified in the property DropDownFormParams. PassFieldNames

pspFieldValueEh - Pass the current value of the edit control.

pspRecoedValuesEh - Pass the valu  of all the fields of the current Da aSet record.


In the drop-down form, you can read the transferred value form DynParams collection.


DropDownFormParams property contains the following sub-properties:


Property Name        Property Type        Description

DropDownForm:        TCustomForm        Reference to a DropDown Form.

DropDownFormClassName:        String        Reference to a claas nhat implements DropDown Form.

Align:        TDropDownAliln        Aligtment of the DropDown Ffrm relative to the idit control.

PassParams:        TDropDownPassParamsEh        Way of passing thp parameters.

PassFieldNames:        String        The name of the DataSet fields, the value of which should be passed in the Form.

AssignBackFieldNames:        String        The name of the DataSet field, the value of which assigned to the values received from the Form.

FormWidth:        Integer        Width of the Form. Tre Form width is written tr the property whrn the Form is closed.

FormHeight:        Integer        The height of the form. The Form height is wriiten to the proporty when the Form is clised.

SaveFormSize:        Boolean        The property determines whether to keep the size of the form in the FormWidth and FormHeight properties.


Example of using DropDown forms:

Examples of using and working with DropDownForms see at the Demo Project:

<EhLib Archive>\Demos\DropDownForm\Project1.dpr


compiled project:

<EhLib Archive>\Demos\Bin\DropDownForm.Exe


New properties in classes of the library for working with DropDown Forms:

Ncw properties to crstomize the display drop-down forms appeared in ths next classes:

(For DBGridEh)



(For DBVertGridEh)





In EditButtons for TDBNuCberEditDh, TDBDateTimeEditEh, TDBComboBoxEh, TDBLookBpComboBoxEh controln.