Wednesday, March 18, 2020

Making a Drop Down List in a DBGrid

Making a Drop Down List in a DBGrid Want to make the best data editing grid ever? Below are instructions for building a user interface for editing lookup fields Inside a DBGrid. Specifically, well be looking at how to place a DBLookupComboBox into a cell of a DBGrid. What this will do is call upon information from a data source that will be used to populate a drop-down box. To show a DBLookupComboBox inside a cell of a DBGrid, you first need to make one available at run time... Create a Lookup With a DBLookupComboBox Select the Data controls page on the Component Palette and pick a DBLookupComboBox. Drop one anywhere on the form and leave the default name of DBLookupComboBox1. It doesnt matter where you put it since most of the time, it will be invisible or floating over the grid. Add one more DataSource and DataSet component to fill the combo box with values. Drop a TDataSource (with the name DataSource2) and TAdoQuery (name it AdoQuery1) anywhere on the form. For a DBLookupComboBox to work properly, several more properties must be set; theyre the key to the lookup connection: DataSource and DataField determine the main connection. The DataField is a field into which we insert the looked-up values.ListSource is the source of the lookup dataset.KeyField identifies the field in the ListSource that must match the value of the DataField field.ListFields is the field(s) of the lookup dataset that are actually displayed in the combo. ListField can show more than one field but multiples should be separated by semicolons.You have to set large enough value for the DropDownWidth (of a ComboBox) to really see multiple columns of data.Heres how to set all the important properties from code (in the forms OnCreate event handler): procedure TForm1.FormCreate(Sender: TObject);beginwith DBLookupComboBox1 dobegin DataSource : DataSource1; // - AdoTable1 - DBGrid1 ListSource : DataSource2; DataField : AuthorEmail; // from AdoTable1 - displayed in the DBGrid KeyField : Email; ListFields : Name; Email; Visible : False; end; DataSource2.DataSet : AdoQuery1; AdoQuery1.Connection : AdoConnection1; AdoQuery1.SQL.Text : SELECT Name, Email FROM Authors; AdoQuery1.Open;end; Note: When you want to display more than one field in a DBLookupComboBox, like in the above example, you have to make sure that all columns are visible. This is done by setting the DropDownWidth property. However, youll see that initially, you have to set this to a very large value which results in dropped list being too wide (in most cases). One workaround is to set the DisplayWidth of a particular Field shown in a drop-down list. This code, placed inside the OnCreate event for the form, ensures that both the author name and its email are displayed inside the drop-down list: AdoQuery1.FieldByName(Email).DisplayWidth:10;AdoQuery1.FieldByName(Name).DisplayWidth:10;AdoQuery1.DropDownWidth:150; Whats left for us to do, is to actually make a combo box hover over a cell (when in edit mode), displaying the AuthorEmail field. First, we need to make sure the DBLookupComboBox1 is moved and sized over the cell in which the AuthorEmail field is displayed. procedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);beginif (gdFocused in State) thenbeginif (Column.Field.FieldName DBLookupComboBox1.DataField) thenwith DBLookupComboBox1 do begin Left : Rect.Left DBGrid1.Left 2; Top : Rect.Top DBGrid1.Top 2; Width : Rect.Right - Rect.Left; Width : Rect.Right - Rect.Left; Height : Rect.Bottom - Rect.Top; Visible : True; end; endend; Next, when we leave the cell, we have to hide the combo box: procedure TForm1.DBGrid1ColExit(Sender: TObject);beginif DBGrid1.SelectedField.FieldName DBLookupComboBox1.DataField then DBLookupComboBox1.Visible : Falseend; Note that when in editing mode, all keystrokes are going to the DBGrids cell but we have to make sure they are sent to the DBLookupComboBox. In the case of a DBLookupComboBox, we are primarily interested in the [Tab] key; it should move the input focus to the next cell. procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);beginif (key Chr(9)) then Exit; if (DBGrid1.SelectedField.FieldName DBLookupComboBox1.DataField) thenbegin DBLookupComboBox1.SetFocus; SendMessage(DBLookupComboBox1.Handle, WM_Char, word(Key), 0); endend; When you pick an item (row) from a DBLookupComboBox, the value or the corresponding KeyField field is stored as the value of the DataField field.

Monday, March 2, 2020

Atomic Radius Definition and Trend

Atomic Radius Definition and Trend Atomic radius is a term used to describe the size of an atom, however, there is no standard definition for this value. An atomic radius may refer to the ionic radius, covalent radius, metallic radius, or van der Waals radius. Atomic Radius Periodic Table Trends No matter what criteria you use to describe the atomic radius, the size of an atom is dependent on how far out its electrons extend. The atomic radius of an element tends to increase the further down you go in an element group. Thats because the  electrons become more tightly packed as you move across the periodic table, so while there are more electrons for elements of increasing atomic number, the atomic radius may decrease. The atomic radius moving down an element period  or column tends to increase because an additional electron shell is added for each new row. In general, the largest atoms are at the bottom lefthand side of the periodic table. Atomic Radius Versus Ionic Radius The atomic and ionic radius is the same for atoms of neutral elements, such as argon, krypton, and neon. However, many atoms of elements are more stable as atomic ions. If the atom loses its outermost electron, it becomes a cation or positively charged ion. Examples include K and Na. Some atoms might lose multiple outer electrons, such as Ca2. When electrons are removed from an atom, it might lose its outermost electron shell, making the ionic radius smaller than the atomic radius. In contrast, some atoms are more stable if they gain one or more electrons, forming an anion or negatively charged atomic ion. Examples include Cl- and F-. Because another electron shell isnt added, the size difference between the atomic radius and ionic radius of an anion isnt as much as for a cation. The anion ionic radius is the same as or slightly larger than the atomic radius. Overall, the trend for the ionic radius is the same as for the atomic radius: increasing in size moving across and decreasing moving down the periodic table. However, its tricky to measure the ionic radius, not least because charged atomic ions repel each other. Measuring Atomic Radius You cant put atoms under a normal microscope and measure their size- although you can kind of do it using an atomic force microscope. Also, atoms dont sit still for examination; they are constantly in motion. Thus, any measure of atomic (or ionic) radius is an estimate that contains a large margin of error. The atomic radius is measured based on the distance between the nuclei of two atoms that are barely touching each other, which means the electron shells of the two atoms are just touching each other. This diameter between the atoms is divided by two to give the radius. Its important, however, that the two atoms dont share a chemical bond (e.g., O2, H2) because the bond implies an overlap of the electron shells or a shared outer shell. The atomic radii of atoms cited in the literature are usually empirical data taken from crystals. For newer elements, the atomic radii are theoretical or calculated values, based on the probable size of the electron shells. How Big Are Atoms? A picometer is 1-trillionth of a meter. The atomic radius of the hydrogen atom is about 53 picometers.The atomic radius of an iron atom is about 156 picometers.The largest measured atom is cesium, which has a radius of about 298 picometers.