Solved

Using num keyboard period as decimal separator

Posted on 2000-03-20
8
474 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
Technology Partners: 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 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 100 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

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!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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