MS Access 97
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,
xx = UIEdit.SelTextwon'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.
Private Sub Title_Exit(Cancel As Integer) global_Selected_Title = Title.SelText End Sub
Computed Fields - Displaying the Date
=Date() =Format(Date(),"Long Date") & " " & Format(Time(),"Long Time")which display as
7/17/02 Wednesday, July 17, 2002 1:23:04 PM
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
This copies selected text in one edit field to another.
procedure TForm1.Button1Click(Sender: TObject); begin edit2.Text := edit1.SelText; end;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.
(Weight_DBEdit.Field as TNumericField).DisplayFormat := '0.00';Use this to get a data value instead of converting a string.
Price := Price_DBEdit.Field.Value;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.
P_per_gm_DBEdit.Field.Value := P_Per_gm; (P_per_gm_DBEdit.Field as TNumericField).Value := P_Per_gm; P_per_gm_DBEdit.Text := floatToStrf(P_Per_gm, ffNumber, 20, 2); // "worked"
Setting Properties at Design Time
Value that was entered | Output mask 0.000 | Output mask 0.### | 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.
(Weight_DBEdit.Field as TNumericField).DisplayFormat := '0.00';In order to access this property at DesignTime, you must explicitly create the Field objects at DesignTime.
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