Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Digit Grouping Numerical Input

Status
Not open for further replies.

kagee

Programmer
Apr 21, 2004
30
NL
How do i display numerical (esp. monetary figures)input as digit grouped input and still derive the actual value while posting to a database
i.e ONE MILLION = 1,000,000 yet post to the db 1000000.


Also how do i write a function that can clear out all input contents in a form (editboxes, list boxex etc)
 
How do i display numerical (esp. monetary figures)input as digit grouped input and still derive the actual value while posting to a database
i.e ONE MILLION = 1,000,000 yet post to the db 1000000

Because your numbers may not always be the same length, you can't use the EditMask. Instead, use the OnGetText of the TField. It would look something like this:
Code:
procedure Table1.GetText(Sender: TField; var Text: String; DisplayText: Boolean)
var 
  i: Integer;
  s: String;
begin
  DisplayText := (not Table1.EditState in [dsEdit, dsInsert]);
  if DisplayText and (Sender.DataType is ftInteger) then
  begin
    text := '';
    s := Sender.Text;
    for i := length(s) downto 1 do
    begin
      text := s[i] + text;
      if (i mod 3 = 0) then
        text := ',' + s;
    end;
  end;
end;

I haven't tested this, but I hope it will point you in the right direction.

To clear the contents of the edits on the form, you'll use the Controls property of the form, something like this:
Code:
  iCount := Form1.ControlCount - 1;
  for i := 0 to iCount do
  begin
    if Form1.Controls[i] is TEdit then
      (Form1.Controls[i] as TEdit).Text:= ''
    else if Form1.Controls[i] is TListbox then
      (Form1.Controls[i] as TListBox).ItemIndex := -1
    else ...//handle other types of controls
  end;

-D
 
I've solved this problem by creating a new component derrived from TEdit.

The main procedures was CMEnter and CMExit:
Code:
    procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
    procedure CMExit(var Message: TCMExit); message CM_EXIT;

At CMEnter, I removed all thousand separators and all the other grouping features.

At CMExit, I added the special Grouping stuff....


//Nordlund
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top