Format EditBox on EditChange

I need to have a EditBox showing the Float format while typing.
I need it to be usefull for float values.
Expl:
Number=123456.789
to be shown as
123,456.789
I repeat : I need it to be shown while typing. If I enter manually this number in Edit4 and do this on a ButtonClick
var
  s:string;
begin
  s:=Edit4.Text;
  s:=StringReplace(s,',','', [rfReplaceAll])  ;
  Edit4.Text:=FormatFloat('#,##00.####',StrToFloat(s))  ;
  Edit4.SelStart := Length(Edit4.Text);
end;
then it works, but I need it to be on EditChange.
Any ideeas?
For integer values it works just fine on EditChange... but I am interested in floating point values.
LVL 11
calinutzAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

calinutzAuthor Commented:
I tryed it with TMaskEdit also but I am not satisfyed. Any other suggestions
Mike LittlewoodEngineerCommented:
Any reason why it needs to be done within EditChange rather than key up/down/press?
calinutzAuthor Commented:
Not really
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

pcsentinelCommented:
look at this link

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21398649.html#13845000

its not for the same format but could be adapted for it

regards
calinutzAuthor Commented:
No reason at all. I only need this Edit format to be shown to the user while he types...
That's all.
So I can use any event...
Thanks for the interest
Mike LittlewoodEngineerCommented:
Try this, might need some slight adjustment

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  i, iLen: Integer;
  s: string;
begin
  i := 0;

  if Trim(Edit1.Text) <> '' then
  begin
    s := Trim(Edit1.Text);
    s := StringReplace(s,',','', [rfReplaceAll]);
    iLen:= Length(s);
    i := Pos('.', s);
    if i = iLen then
      s := Copy(s, 1, iLen-1);

    if Trim(s) <> '' then
      s := FormatFloat('#,###0.####',StrToFloat(s));

    if i = iLen then
      s := s + '.';

    Edit1.Text := s;
    Edit1.SelStart := Length(Edit1.Text);
  end;
end;
Mike LittlewoodEngineerCommented:
I would also put in a

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if (Pos('.', Edit1.Text) > 0) and (key = '.') then
    key := #0;
end;

so that it isnt trying to duplicate decimal points

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
calinutzAuthor Commented:
Thanks. It works fine with minor adjustments.
Mike LittlewoodEngineerCommented:
Ok great Calinutz, thought it might need a little bit of tinkering, but got the general idea down.

Glad I could help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.