在Delphi中,如何使货币数据类型以不同的货币以不同的形式显示? [英] In Delphi, how can you have currency data types shown in different currencies in different forms?

查看:160
本文介绍了在Delphi中,如何使货币数据类型以不同的货币以不同的形式显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个Delphi应用程序,该应用程序从数据库中的各个表中提取条目,并且不同的条目将具有不同的币种。因此,我需要为每种Currency数据类型($,Pounds,Euros等)显示不同的小数位数和货币字符,具体取决于我加载的商品的货币。

I need to write a Delphi application that pulls entries up from various tables in a database, and different entries will be in different currencies. Thus, I need to show a different number of decimal places and a different currency character for every Currency data type ($, Pounds, Euros, etc) depending on the currency of the item I've loaded.

有没有一种方法可以在几乎全局范围内更改货币,也就是说,对于以表格形式显示的所有Currency数据?

Is there a way to change the currency almost-globally, that is, for all Currency data shown in a form?

推荐答案

即使使用相同的货币,也可能需要显示不同格式的值(例如,分隔符),所以我建议您将LOCALE而不是仅将货币与您的值相关联。

您可以使用简单的Integer来保存LCID(语言环境ID)。

请在此处查看列表: http://msdn.microsoft.com/zh-cn/library/0h88fahh.aspx

Even with the same currency, you may have to display values with a different format (separators for instance), so I would recommend that you associate a LOCALE instead of the currency only with your values.
You can use a simple Integer to hold the LCID (locale ID).
See the list here: http://msdn.microsoft.com/en-us/library/0h88fahh.aspx

然后显示值,使用类似这样的东西:

Then to display the values, use something like:

function CurrFormatFromLCID(const AValue: Currency; const LCID: Integer = LOCALE_SYSTEM_DEFAULT): string;
var
  AFormatSettings: TFormatSettings;
begin
  GetLocaleFormatSettings(LCID, AFormatSettings);
  Result := CurrToStrF(AValue, ffCurrency, AFormatSettings.CurrencyDecimals, AFormatSettings);
end;

function USCurrFormat(const AValue: Currency): string;
begin
  Result := CurrFormatFromLCID(AValue, 1033); //1033 = US_LCID
end;

function FrenchCurrFormat(const AValue: Currency): string;
begin
  Result := CurrFormatFromLCID(AValue, 1036); //1036 = French_LCID
end;

procedure TestIt;
var
  val: Currency;
begin
  val:=1234.56;
  ShowMessage('US: ' + USCurrFormat(val));
  ShowMessage('FR: ' + FrenchCurrFormat(val));
  ShowMessage('GB: ' + CurrFormatFromLCID(val, 2057)); // 2057 = GB_LCID
  ShowMessage('def: ' + CurrFormatFromLCID(val));
end;

这篇关于在Delphi中,如何使货币数据类型以不同的货币以不同的形式显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆