Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MaskEdit control input and display control

Posted on 2004-09-09
7
Medium Priority
?
4,481 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
Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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