[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Format EditBox on EditChange

Posted on 2005-05-11
9
Medium Priority
?
394 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:calinutz
  • 4
  • 4
9 Comments
 
LVL 11

Author Comment

by:calinutz
ID: 13977221
I tryed it with TMaskEdit also but I am not satisfyed. Any other suggestions
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13977275
Any reason why it needs to be done within EditChange rather than key up/down/press?
0
 
LVL 11

Author Comment

by:calinutz
ID: 13977350
Not really
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Expert Comment

by:pcsentinel
ID: 13977478
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
0
 
LVL 11

Author Comment

by:calinutz
ID: 13977481
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
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13979008
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;
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 500 total points
ID: 13979099
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
0
 
LVL 11

Author Comment

by:calinutz
ID: 13993961
Thanks. It works fine with minor adjustments.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13994075
Ok great Calinutz, thought it might need a little bit of tinkering, but got the general idea down.

Glad I could help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question