Search results for 'Decimal Separator'. 1 post(s) found.
- 2007/08/25 How To Force The Correct Decimal Separator
Some English speaking countries use the "point" as Decimal Separator, while the rest of the world is using the "Comma". How can you make sure that the user will press the correct key when entering a number with a decimal fraction? With the code in this examples, it doesn't matter!
// Correct the Decimal Separator
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
// Delphi automatically sets DecimalSeparator (a global
// variable) to Windows' Decimal Separator
if Key in ['.', ','] then
Key := DecimalSeparator;
end;
// This is a more complete procedure:
// it allows only valid numbers and
// it corrects the Decimal Separator.
// For educational purposes 8-)
// the code is very detailed.
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
type
TErrNum = (eNone, eInvalidKey, eTooManySeps, eTooManySigns, eSignPos);
const
ErrMessages : array[eInvalidKey..eSignPos] of string = (
'Invalid key',
'Only one Decimal Separator is allowed',
'Only one sign is allowed',
'A sign is only allowed in the first position');
Signs = ['+', '-'];
Nums = ['0'..'9'];
DecSeps = ['.', ','];
Backspace = [#8];
ValidKeys = Signs + Nums + DecSeps + Backspace;
var
ErrNum: TErrNum;
begin
ErrNum := eNone;
if not (Key in ValidKeys) then
ErrNum := eInvalidKey
else if Key in DecSeps then begin
Key := DecimalSeparator;
if Pos(Key, Edit2.Text) > 0 then
ErrNum := eTooManySeps;
end
else if Key in Signs then begin
if Pos('+', Edit2.Text) + Pos('-', Edit2.Text) > 0 then
ErrNum := eTooManySigns
else if Edit2.SelStart <> 0 then
ErrNum := eSignPos;
end;
if ErrNum <> eNone then begin
Key := #0; // nothing is passed to the Edit
MessageDlg(ErrMessages[ErrNum], mtWarning, [mbOk], 0);
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
// Delphi automatically sets DecimalSeparator (a global
// variable) to Windows' Decimal Separator
if Key in ['.', ','] then
Key := DecimalSeparator;
end;
// This is a more complete procedure:
// it allows only valid numbers and
// it corrects the Decimal Separator.
// For educational purposes 8-)
// the code is very detailed.
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
type
TErrNum = (eNone, eInvalidKey, eTooManySeps, eTooManySigns, eSignPos);
const
ErrMessages : array[eInvalidKey..eSignPos] of string = (
'Invalid key',
'Only one Decimal Separator is allowed',
'Only one sign is allowed',
'A sign is only allowed in the first position');
Signs = ['+', '-'];
Nums = ['0'..'9'];
DecSeps = ['.', ','];
Backspace = [#8];
ValidKeys = Signs + Nums + DecSeps + Backspace;
var
ErrNum: TErrNum;
begin
ErrNum := eNone;
if not (Key in ValidKeys) then
ErrNum := eInvalidKey
else if Key in DecSeps then begin
Key := DecimalSeparator;
if Pos(Key, Edit2.Text) > 0 then
ErrNum := eTooManySeps;
end
else if Key in Signs then begin
if Pos('+', Edit2.Text) + Pos('-', Edit2.Text) > 0 then
ErrNum := eTooManySigns
else if Edit2.SelStart <> 0 then
ErrNum := eSignPos;
end;
if ErrNum <> eNone then begin
Key := #0; // nothing is passed to the Edit
MessageDlg(ErrMessages[ErrNum], mtWarning, [mbOk], 0);
end;
end;
Another posts included in "Delphi"
| How To Change Screen Resolution (0) | 2007/08/25 |
| How To Check If A Soundcard Is Installed (0) | 2007/08/25 |
| How To Open Url In Default Webbrowser (0) | 2007/08/25 |
| How To Register Own File Types (0) | 2007/08/25 |
| How To Get Volume Name (0) | 2007/08/25 |
| How To Get Windows And System Directory (0) | 2007/08/25 |
| Get The Drive Type (0) | 2007/08/25 |
| How can I modify aliases programmatically ? (0) | 2007/08/25 |
Trackback : Cannot send a trackbact to this post.
-
Subject Get propecia online pharmacy.
2008/12/14 05:20
Propecia. Propecia merck propecia online uk. Propecia side effects finasteride. Propecia sexual side effects. Buy propecia international pharmacy. Danger propecia.
-
Subject Phentermine.
2008/12/18 01:02
Phentermine. Order phentermine.
-
Subject Soma.
2008/12/18 04:00
Soma addiction and lying. Drug soma.
-
Subject different money making ideas
2010/01/29 00:50
moneyideas
-
Subject different money making ideas
2010/01/29 09:16
moneyideas
-
Subject different money making ideas
2010/01/31 16:45
moneyideas

Prev

Rss Feed