Databases - UIEdit Fields

Most forms have controls where the user can type data. I term these UIEdit fields (User Interface Edit).

MS Access | Delphi

MS Access 97

Implemented via Text Box on the tool palette.

In order to read or write most parameters, you must first move the focus to the field - [Title].SetFocus

Of course, you can't modify the visible property of any field which has the focus.

I have a situation where I want the user to select data in a field and then press a button. Unfortunately,

won't work unless SetFocus is executed first. Of course, SetFocus selects the entire field and the user's selection is lost. To fix this, I created a global variable and set it when the focus leaves the field.

Computed Fields - Displaying the Date

It is possible for a Text Box to display the result of an expression. Here are 2 methods of indicating today's date which display as

If you use the menu selection Insert / Date and Time..., MS Access will generate a component and format string based on your selections.

Delphi 5.0

UIEdit is either a TEdit or a TDBEdit control.

This copies selected text in one edit field to another.

To work with databases, you normally use DB Controls - TDBEdit. This sets the display to 2 decimal places. Place it in the form's constructor. Use this to get a data value instead of converting a string. There is no way to force a TEdit to right align numbers (TDBEdit does it automatically), and my system crashes when I try to define fields for a TTable (required to create an unattached TDBEdit), therefore I display calculated values in a TLabel.

I was able to run the field editor by right clicking the TTable and selecting Fields Editor.... However, setting Alignment to taRightJustify had no effect. Neither did setting currency to true. Directly setting its value caused an access violation. The first 2 failed, the 3rd wrote a left aligned value.

Setting Properties at Design Time

By default, Field objects are created automatically and are not available at design time. In general, that's fine. However, I had a floating point number with way too many decimal places that I wanted to show differently in design view.

Value that was enteredOutput mask
Output mask
No Mask
27.8 27.800 27.8 27.7999992370605
1.40 1.400 1.4 1.39999997615814
172.65 172.650 172.65 172.649993896484

This "problem" is caused by how floating point numbers are stored (which causes many decimal fractions to not have exact representations). There are several "fixes", controlling the display format is one.

The "output mask" is stored in the DisplayFormat property. This is one way to access it at runtime.

In order to access this property at DesignTime, you must explicitly create the Field objects at DesignTime. Once one Field object is explicitly created, the others won't be automatically created - thus you have to explicitly create all the ones you want.

Form Creation Order

When using DataModules, you might get access violations if you create the form before the database is opened. (I did when I set the DisplayFormat property in TForm1.FormCreate.) Delphi automatically sets the form creation order. You can modify the creation order in 2 ways

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Databases / UIEdit_Fields.html