Solved

MaskEdit control input and display control

Posted on 2004-09-09
7
4,185 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
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 300 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 200 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 71
Delphi 2 47
FMX and jaudiotracker playing memory stream 29 66
Firemonkey android show image from resource ? 1 32
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now