Solved

Using num keyboard period as decimal separator

Posted on 2000-03-20
8
473 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 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