Solved

Using num keyboard period as decimal separator

Posted on 2000-03-20
8
469 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
 
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
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.

 

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

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

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…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

12 Experts available now in Live!

Get 1:1 Help Now