?
Solved

MaskEdit control input and display control

Posted on 2004-09-09
7
Medium Priority
?
4,396 Views
Last Modified: 2012-06-27
Hi all,

I need to allow a user to enter a value (which may contain up to a maximum of 3 digits after the decimal), but I need to then display it as a fixed 3 digits after the decimal as well as indicate the thousands seperator.

I am actually using Devexpress TcxMaskEdit (which allow using of regular expressions in the mask), but if you have any answer, I would like to know.

Example:

Input Value:                     Display Value (after input):
23                                   23.000
2134.34                           2,134.340

Regards,
Js
0
Comment
Question by:johan777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 12023005
We use the TurboPower Orpheus TOvcNumericField for that with a picture mask of #.###.###,### for that.

(The Orpheus library is open source on sourceforge now)

Regards Jacco
0
 
LVL 7

Accepted Solution

by:
sftweng earned 900 total points
ID: 12023162
How about this, no special components required:

unit uQ21125564;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    procedure Edit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1Change(Sender: TObject);
var
  inputString, outputString : String;
  realNumber : Real;
begin
  inputString := Edit1.Text;
  try
    realNumber := StrToFloat(inputString);
    CurrencyString := '';
    ThousandSeparator := ',';
    outputString := Format('%.3m',[realNumber]);
  except
    outputString := '??';
  end {try};
  Label1.Caption := outputString;
end;

end.
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 600 total points
ID: 12023903
if you need it for a database-entry,
then you could use a tdbedit-field directly bound to you field

to get the output in your format, simple assign a displayformat then like

//in the afteropen-event of your dataset use
  TFloatField(Dataset.FieldByName('FieldName')).DisplayFormat := '#,##0.000';

well, just in case that you need this for a database-entry

meikl ;-)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 12025042
This is not a component solution, btw maybe can help.
I've this my old function to format digits...

function FormatDigits(Value: Extended;
                     Digits: Cardinal): String;
var
  Fmt: String;
begin
   Fmt := '#,###';
   If Digits > 0 then begin
      Fmt := Fmt+'.';
      while Digits > 1 do
         begin
            Fmt := Fmt+'#';
            dec(Digits);
         end;
      Fmt := Fmt+'0';
      end;
   Result := FormatFloat(Fmt,Value);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Showmessage(FormatDigits(1100.1258796,3));
Showmessage(FormatDigits(1100.1258796,5));
Showmessage(FormatDigits(1100.1,6));
Showmessage(FormatDigits(1100.1258796,0));
end;
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12034184
BTW, just to make the code a bit "cleaner", you might like to add:
    DecimalSeparator := '.';
and save the prior settings and then restore them in the Edit1Change event handler.
0
 
LVL 7

Expert Comment

by:sftweng
ID: 12043939
Doh! This is a bit easier:

procedure TForm1.Edit1Change(Sender: TObject);
var
  inputString, outputString : String;
  realNumber : Real;
begin
  inputString := Edit1.Text;
  try
    realNumber := StrToFloat(inputString);
    outputString := Format('%.3n',[realNumber]);
  except
    outputString := '??';
  end {try};
  Label1.Caption := outputString;
end;
0
 

Author Comment

by:johan777
ID: 12565125
Hi all,

In short: The Devexpress component TMaskEdit does not have the ability to accommodate the thousands seperator, but their TCurrencyEdit component does. So, I decided to use this component and delete the currency symbol which then gives me exactly what I was looking for.

Thanx for all the help! I'm going to allocate the points based on the excellent alternative solutions I received.

Regards,
Johan Swart

PS: Sorry for only getting around to resolve this now, but the project I'm on was keeping me a bit busy ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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