Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using num keyboard period as decimal separator

Posted on 2000-03-20
8
Medium Priority
?
481 Views
Last Modified: 2010-04-04
In spanish the decimal separator is "," the problem is that on the Number Keypad the decimal separator send a ".".

On the other hand Delphi understands that on number fields the separatos must be "," and it doesn't allow any other char.

What I am trying to do is that when you press the deciman separator on the numeric keypad the application understand the "," instead of the ".",  I have tryed to us the OnKeyDown event, but it seems to detect the key before that events ocurs.  

I have seen MS Excel to do it correctly.  Any ideas?
0
Comment
Question by:clopez
8 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 2635646


procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
   if Key = '.' then
     Key:=',';
end;


Cheers,
Igor.
0
 

Expert Comment

by:blackthorne
ID: 2635648
If you are use a TField  you can use this  Field.ValidChars := ield.ValidChars +  [','];
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2635655
You can do it not only for desired edit control, but for whole form. Set Form1.KeyPreview = true,  then write Form1.onKeyPress method:
-----
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
   if key = '.'
   then key := ',';
end;
----


Igor.
0
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.

 
LVL 9

Expert Comment

by:ITugay
ID: 2635680
to blackthorne.

PLEASE use a "comment", instead an "answer" if you not first in queue or not ABSOLUTELY sure in your answer.

best regards,
Igor.
0
 

Expert Comment

by:blackthorne
ID: 2635691
blackthorne changed the proposed answer to a comment
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2636207
Hello,
Either you change this in the locale windows regional settings
or in your case you can use the global variable DecimalSeparator to suit your needs.
Change it to whatever you want...

Regards.
0
 
LVL 4

Accepted Solution

by:
DMN earned 300 total points
ID: 2637882
I think desired solution must change dot to decimal separator in only case NUMPAD DOT was pressed. To do so set Form.KeyPreview property to True. Then add boolean variable CHECKDECIMAL to private (or protected, or public) section of form declaration. Then define Form.OnKeyDown and Form.OnKeyPress events:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  {Set flag if Numpad dot was pressed}
  if (Key=VK_DECIMAL) and (Shift=[]) then
    CheckDecimal := True;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  {Replace '.' with decimal separator if Numpad Dot was pressed}
  if (Key='.') and CheckDecimal then
    begin
      Key := DecimalSeparator;
      {Now reset the flag}
      CheckDecimal := False;
    end;
end;



Add these methods to every form in your project or inherite all your forms from one with these events defined.

Hope this helps.
Alexander.
0
 

Author Comment

by:clopez
ID: 2639569
The accepted answer not only changes the "." to a ",", but makes sure that then pressed key was then Decimal Key in the keypad.  That is exactly what I was looking for.  Thanks to all
0

Featured Post

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.

Question has a verified solution.

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

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

916 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