Running delphi program with different setting for number format

Hello, we have a Delphi Program (running under windows) that only runs correctly when the OS is set to english number format, i.e. the dot .  as decimal separator. As we are in Germany this means changing the number format every time.

I spent some time trying to convince delphi to use the dot regardless what locale is set but I could not get this working. Then I thought it might be possible to set environment variables before executing the program; I set LANG to "en" but this does not seem to influence the decimal separator. Is there another environment variable for this or another way to run a program with specific language/number settings?

Thank you for a hint,
jc
is-olAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThommyCommented:
Explicitly set the decimal separator in your application to english version overwriting system settings

procedure TForm1.FormCreate(Sender: TObject);
var
  SystemDecimalSep: char;
begin
  SystemDecimalSep :=  DecimalSeparator;
  DecimalSeparator := '.';  //fix decimal separator to english number format
end;
0
ThommyCommented:
0
Sinisa VukCommented:
Changing DecimalSeparator is one way. Second is to make "non-sensitive" application. If you use Delphi "native" components a right way then you are on track. Did you detect places where you have problems with that? Things can be written correctly ... If it is DB application - use DB components, they will post values in db correctly. If you must build sql in code - do number transformations as is shown in second Thommy's post (link).
Post some example of your problematic code here.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

is-olAuthor Commented:
Hi, thank you all, its not my own code ant it's ~ 10k lines.... I will try to determine where exactly the "wrong" conversion is being done and then get back here.
0
Pierre CorneliusCommented:
what version of delphi are you using?

In Delphi 2009 you can use the global variable DecimalSeparator (declared in SysUtils unit) e.g. DecimalSeparator:= '.';

In Delphi XE3 you can use the global variable FormatSettings.FormatSettings.DecimalSeparator (declared in SysUtils unit) e.g. FormatSettings.DecimalSeparator = '.';

Where? I would suggest putting it in your program file (click on Project, view source).

Take note that these are globals and not thread safe, so if your app uses multi-threading you need to take that into account. In such case it would be better to supply functions using format settings with a variable in each case e.g. (for Delphi XE3):

function SomeValFormattedAsCurr(val: double): string;
var fs: TFormatSettings;
begin
  fs:= TFormatSettings.Create;
  fs.DecimalSeparator:= '-';
  fs.ThousandSeparator:= ',';
  result:= FormatFloat('#,##0.00', val, fs);
end;

Open in new window


Side-note:
Thread safety should not really be an issue as you probably won't be changing the format all the time anyway - probably only once at application startup.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
you can set it to what you like and if you have policies running every so often the policy may reset it to what the company dictates as user defaults

unless you deactivate this

on create of mainform:

DecimalSeparator := '.';
Application.UpdateFormatSettings := False;
0
is-olAuthor Commented:
Thank you for the hints, unfortunately I could not yet check whether that helps as our internet connection broke down. I hope to finish that tomorrow. Regards,jc
0
is-olAuthor Commented:
Yes, that seems to be the solution, now I started to use local FormatSettings and I can read in the data independent from the locale setting. Thank you very much!
0
Pierre CorneliusCommented:
May I ask why the B grade?
0
ThommyCommented:
May I ask why I didn't get any points????
I was the first who suggested setting DecimalSeparator at runtime...
0
Sinisa VukCommented:
My hint stay the same. Always try to be independent regarding to a date/number format.
I you app will be international - you will have a problem.
0
is-olAuthor Commented:
Sorry, PierreC, I did not use EX much up to now so I am not really familiar with the grades. I thought this is the normal grade for a "good" solution. Thommy, I tried your code but this did not work for me. I set the Decimal separator variable everywhere but only after using  local TFormatSettings in every format statement I got round the issue. Maybe that is due to the specific usage of string conversions in the code. Sinisav, the data in question is coming in from a SQL database with a fixed format. Naturally I only apply the local settings to these data, not to all other values that are and should be locale-dependent. Thank you all for helping!
0
Pierre CorneliusCommented:
You should have awarded an A grade.

Here are some guidelines for future reference:
http://support.experts-exchange.com/customer/portal/articles/481419
0
is-olAuthor Commented:
Ok I see. Seems I cannot correct this now. I will heed to the guidelines in future, sorry.
0
Pierre CorneliusCommented:
No problem. At least you know for next time.
0
is-olAuthor Commented:
Since an admin reopened the question I now tried to award points to all who helped. I award PierreC 210 pts as this code piece finally did the trick. Sorry for misinterpreting EE's grade system.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.