[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Is there anyway to make my program work with only one regional config

Hi experts, Is there a way to my program work with only one regional config, I mean this way always the datatime config, and the other configs will be the same, does not matter what config is on the regional config.
0
rafaelrgl
Asked:
rafaelrgl
2 Solutions
 
MerijnBSr. Software EngineerCommented:
i'm quite sure you can set the LongDateFormat, ShortTimeFormat etc variables to your liking.

Set it at startup of your application and all your calls to i.e. DateTimeToStr() will use that format.
0
 
kfoster11CEOCommented:
You need to do this without effecting any other applications.

If you send a TFormatSettings into all of your calls then it will work just for your app.  Here's an example

var
    Fmt     : TFormatSettings;  
    s         : string;
begin
    GetLocaleFormatSettings(GetThreadLocale,Fmt);
    fmt.ShortDateFormat := 'yyyymmdd';
    DateToStr(s, fmt);
    ShowMessage(s);
end;
--------------------------
What you need to do is to declare a global variable somewhere and configure it during your systems's initialization.  Then do a find in files for each call to a date or time function and add the global TFormatSettings parameter.

0
 
MerijnBSr. Software EngineerCommented:
these variables are local only
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rafaelrglAuthor Commented:
I try to put this on my code:

const
  ShortDateFormat = 'M/d/yyyy';
  LongTimeFormat  = 'hh:nn:ss AM/PM';



procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption := datetimetostr(now());
  label2.Caption := ShortDateFormat + ' ' + LongTimeFormat ;
end;


the result from this is: the label2 never change when i change the regional config. but the label1, always change to be like the regional config, also the function above, It's not work becouse i'm going to do something like this below on my code:

now() + datetimetostr()
0
 
MerijnBSr. Software EngineerCommented:
this is because you have two constants declared with the same name as these variables you are changing:

const
  ShortDateFormat = 'M/d/yyyy';
  LongTimeFormat  = 'hh:nn:ss AM/PM';

You should rename these constants so they don't conflict with the other variables.


>
> now() + datetimetostr()
>

I don't understand what you want to do with this, it won't compile?
0
 
wavgetCommented:
I believe you have to add the following to FormCreate to prevent your settings from changing:

Application.UpdateFormatSettings := False;
0
 
rafaelrglAuthor Commented:
it work great guys, thanks so much!!!

here is the code, if anybody wants, try to change the regional config when the program is running then click on the butto to check, then nothing will change. lol, that's what i want. by guys, thanks for the help.




unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  ShortDateFormat = 'M/d/yyyy';
  LongTimeFormat  = 'hh:nn:ss AM/PM';

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    label1.Caption := DateTimeToStr(now());
    label2.Caption := ShortDateFormat  + ' ' + LongTimeFormat;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.UpdateFormatSettings := False;
end;

end.
0
 
rafaelrglAuthor Commented:
i find out something, we don't need this lines here:

const
  ShortDateFormat = 'M/d/yyyy';
  LongTimeFormat  = 'hh:nn:ss AM/PM';


it work normally only with: Application.UpdateFormatSettings := False;

this way the regional config can change when my program is running, but my program keep the original regional config until start again. thanks
0
 
rafaelrglAuthor Commented:
ok, with variable is to set the number on the application, i mean, here in eua is 99.00 and on brazil is 99,00

talking about date, the variables are:

const
  ShortDateFormat = 'M/d/yyyy';
  LongTimeFormat  = 'hh:nn:ss AM/PM';

what about numbers????/
 
  ????????? = '99.99'????
0
 
MerijnBSr. Software EngineerCommented:
these are kept in the variables DecimalSeperator and ThousandsSeperator.
You can avoid they change with the same Application.UpdateFormatSettings := false; command
0
 
rafaelrglAuthor Commented:
i got it, thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now