Discussion:
Case statement
(too old to reply)
Frank
2003-08-15 17:16:29 UTC
Permalink
The following is a case statement that I use in my program. As you can see,
in order to check whether the digit keyed is the Decimal Separator, I have
been forced to use both characters, comma and full point.This gives me
problem later. I really need to check for the Decimal Separator, but I
couldn't find the way, since Delphi expects a constant expression. I thank
in advance whoever has a suggestion on how to achieve what I need.

case Key of
'0'..'9' , '+', '-':
begin
......
end;

'.' , ',':
begin
......
end;
Maarten Wiltink
2003-08-15 18:05:58 UTC
Permalink
Frank wrote in message ...
Post by Frank
The following is a case statement that I use in my program. As you can see,
in order to check whether the digit keyed is the Decimal Separator, I have
been forced to use both characters, comma and full point.This gives me
problem later. I really need to check for the Decimal Separator, but I
couldn't find the way, since Delphi expects a constant expression. I thank
in advance whoever has a suggestion on how to achieve what I need.
case Key of
begin
......
end;
begin
......
end;
You are totally correct that Delphi expects a *constant* expression,
and the DecimalSeparator variable isn't.

There is no way you can beat this restriction of the case statement.
None.

But everything that can be expressed as a case statement, can be
expressed as an if statement.

Groetjes,
Maarten Wiltink
Frank
2003-08-16 08:47:40 UTC
Permalink
I changed to an if satatement, but I am curious on how to implement Maarten
suggestion. How do I set a constant differently depending on the
DecimalSeparator ?
<snip>
Post by Maarten Wiltink
You are totally correct that Delphi expects a *constant* expression,
and the DecimalSeparator variable isn't.
There is no way you can beat this restriction of the case statement.
None.
Unless you pre-process the data to convert whatever funny locale
decimal character is used into something constant ...
Post by Maarten Wiltink
But everything that can be expressed as a case statement, can be
expressed as an if statement.
Groetjes,
Maarten Wiltink
J French
2003-08-16 09:43:11 UTC
Permalink
Post by Frank
I changed to an if satatement, but I am curious on how to implement Maarten
suggestion. How do I set a constant differently depending on the
DecimalSeparator ?
It was not actually Maaren's suggestion
- he pointed out that Case deals with Constants - and that is it

I (seditiously) pointed out that you could simply bypass the problem
by pre-processing the string to remove its Locale specific nonsense.

While I agree that some rather unsophisticated users prefer to see ','
used as the decimal point, it is simply asking for problems to use
that in any data storage - or any data that might be transmitted to
other locales.

Also it is really difficult testing code that deals with multiple
locales - if one relies on the Windows settings.

One can of course build in a 'Locale Switch'

There is a nice little procedure called Val() that is non-locale
aware, as if (IIRC) Str()

Naturally I'll get a blast from Norway (and maybe Spain) for
suggesting this, however, I firmly believe that the 'locale' stuff
should be purely a 'presentaion layer'.
Maarten Wiltink
2003-08-16 11:52:14 UTC
Permalink
J French wrote in message <***@news.btclick.com>...
[...]
Post by J French
While I agree that some rather unsophisticated
... or Dutch ...
Post by J French
users prefer to see ','
used as the decimal point, it is simply asking for problems to use
that in any data storage - or any data that might be transmitted to
other locales.
[...]
Post by J French
Naturally I'll get a blast from Norway (and maybe Spain) for
suggesting this, however, I firmly believe that the 'locale' stuff
should be purely a 'presentation layer'.
And you're right. So what is your problem with users who want to
_see_ any character used for the decimal separator? (Not the decimal
point. That's your Anglocentrism piping up again.)

Groetjes,
Maarten Wiltink
J French
2003-08-16 12:10:54 UTC
Permalink
On Sat, 16 Aug 2003 13:52:14 +0200, "Maarten Wiltink"
<***@kittensandcats.net> wrote:

<snip>
Post by Maarten Wiltink
[...]
Post by J French
Naturally I'll get a blast from Norway (and maybe Spain) for
suggesting this, however, I firmly believe that the 'locale' stuff
should be purely a 'presentation layer'.
And you're right. So what is your problem with users who want to
_see_ any character used for the decimal separator? (Not the decimal
point. That's your Anglocentrism piping up again.)
<blank line>

Having lived with USA Date Formats since well before Windows was
invented, I'm pretty happy about 'abstracting' presentation from
internal formats.

What starts off as a nuisance evolves into a pretty good idea

If users really want to see a paper clip - or a cute little puppy dog
instead of the decimal point, then I'll do it for them - at a price.

I've worked on a couple of systems where the numeric output was
'hybrid' - some stuff coming out as 1,000.00 and others as 1.000,00
- as per users requirements
- and see no reason why this sort of stuff should be buried deep in an
OS or language
- it strikes me as downright dangerous
Maarten Wiltink
2003-08-16 14:01:13 UTC
Permalink
J French wrote in message <***@news.btclick.com>...

<localisation>
Post by J French
What starts off as a nuisance evolves into a pretty good idea
If users really want to see a paper clip - or a cute little puppy dog
instead of the decimal point, then I'll do it for them - at a price.
I've worked on a couple of systems where the numeric output was
'hybrid' - some stuff coming out as 1,000.00 and others as 1.000,00
- as per users requirements
- and see no reason why this sort of stuff should be buried deep in an
OS or language
- it strikes me as downright dangerous
Having OS support is usually a good thing; it keeps developers
alert to things. And I've been annoyed at having to juggle the
DecimalSeparator variable, too. What it means, though, is probably
that my program didn't get its things right, and there should have
been an integer, not a string, at that point.

Groetjes,
Maarten Wiltink

Bob Richardson
2003-08-15 20:13:17 UTC
Permalink
Post by Frank
The following is a case statement that I use in my program. As you can see,
in order to check whether the digit keyed is the Decimal Separator, I have
been forced to use both characters, comma and full point.This gives me
problem later. I really need to check for the Decimal Separator, but I
couldn't find the way, since Delphi expects a constant expression. I thank
in advance whoever has a suggestion on how to achieve what I need.
case Key of
begin
......
end;
begin
......
end;
This solution is closest to your current coding:

if key = DecimalSeparator then
....
else case key of...
...
Bjørge Sæther
2003-08-15 20:26:11 UTC
Permalink
Post by Frank
The following is a case statement that I use in my program. As you can see,
in order to check whether the digit keyed is the Decimal Separator, I have
been forced to use both characters, comma and full point.This gives me
problem later. I really need to check for the Decimal Separator, but I
couldn't find the way, since Delphi expects a constant expression. I thank
in advance whoever has a suggestion on how to achieve what I need.
case Key of
begin
......
end;
begin
if Key = DecimalSeparator then begin

end
else if Key = ThousandSeparator then begin

end
Post by Frank
end;
In e.g. Norway, #160 is used for decimalseparator....
--
Regards,

Bjørge Sæther
***@haha_itte.no
-------------------------------------
I'll not spend any money on American Software products
until armed forces are out of Iraq.
"Frank" <***@virgilio.it> skrev i melding news:Nz8%a.6281$***@news1.tin.it...
Frank
2003-08-16 08:47:41 UTC
Permalink
How #160 is represented on the keyboard ? I thought the only possible
Decimal separators were '.' and ',' !
Post by Bjørge Sæther
Post by Frank
The following is a case statement that I use in my program. As you can
see,
Post by Frank
in order to check whether the digit keyed is the Decimal Separator, I have
been forced to use both characters, comma and full point.This gives me
problem later. I really need to check for the Decimal Separator, but I
couldn't find the way, since Delphi expects a constant expression. I thank
in advance whoever has a suggestion on how to achieve what I need.
case Key of
begin
......
end;
begin
if Key = DecimalSeparator then begin
end
else if Key = ThousandSeparator then begin
end
Post by Frank
end;
In e.g. Norway, #160 is used for decimalseparator....
--
Regards,
Bjørge Sæther
-------------------------------------
I'll not spend any money on American Software products
until armed forces are out of Iraq.
Dr John Stockton
2003-08-15 20:44:55 UTC
Permalink
JRS: In article <Nz8%a.6281$***@news1.tin.it>, seen in news:comp.lang.pascal.delphi.misc, Frank <***@virgilio.it> posted at
Fri, 15 Aug 2003 17:16:29 :-
Post by Frank
The following is a case statement that I use in my program. As you can see,
in order to check whether the digit keyed is the Decimal Separator, I have
been forced to use both characters, comma and full point.This gives me
problem later. I really need to check for the Decimal Separator, but I
couldn't find the way, since Delphi expects a constant expression. I thank
in advance whoever has a suggestion on how to achieve what I need.
if Key = DecimalSeparator then Point
else case Key of ...

If there is only one Case left, it can be replaced by if Key in [...]
then ...
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Loading...