Solved

Using num keyboard period as decimal separator

Posted on 2000-03-20
8
467 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
Comment Utility


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


Cheers,
Igor.
0
 

Expert Comment

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

Expert Comment

by:ITugay
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:blackthorne
Comment Utility
blackthorne changed the proposed answer to a comment
0
 
LVL 4

Expert Comment

by:jeurk
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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