当 VAR_LOCALE_USER_DEFAULT 作为参数提供时,什么会导致 VarDateFromStr 无法使用当前用户的区域设置

发布于 2024-10-02 14:55:41 字数 866 浏览 0 评论 0原文

这是该问题的后续问题。

正如所问,当 VAR_LOCALE_USER_DEFAULT 作为参数提供时,什么会导致 VarDateFromStr(来自 Oleaut32.dll)无法使用当前用户的区域设置?

因此,我们的应用程序遇到了很多问题。

在有问题的系统上,如果我们执行以下代码:

procedure TForm1.Button3Click(Sender: TObject);
var V : Variant;
    dte : TDateTime;
begin
  V := Label28.Caption;
  dte := VarAsType(V,varDate) ; //Implicitly calls VarDateFromStr
  V := dte;
  Label28.Caption := V; //Implicitly calls VarBStrFromDate
end;

Label28 以标题“11-05-2010”开头,标题将在每次调用之间从 11-05-2010 到 05-11-2010 交替。

在给定系统上,GetLocaleStr(GetThreadLocale, LOCALE_SSHORTDATE, 'm/d/yy') 返回“dd-MM-yyyy”(当前用户的短日期格式)

该问题发生在 WinXP SP3 上。 (虽然我们的应用程序未在任何其他操作系统版本上使用,但不能说它是否特定于该版本)。

我最初的想法是,这可能与安全相关(用户的安全是无懈可击的),但我还无法证明这一点。

This is a follow-up from that question.

As asked, what can make VarDateFromStr (from Oleaut32.dll) fail to use the current user's Locale when VAR_LOCALE_USER_DEFAULT is supplied as an argument?

Our app encountered quite a few problems because of this.

On systems with the problem, if we execute the following code:

procedure TForm1.Button3Click(Sender: TObject);
var V : Variant;
    dte : TDateTime;
begin
  V := Label28.Caption;
  dte := VarAsType(V,varDate) ; //Implicitly calls VarDateFromStr
  V := dte;
  Label28.Caption := V; //Implicitly calls VarBStrFromDate
end;

with Label28 starting with a caption of "11-05-2010", the caption will alternate from 11-05-2010 to 05-11-2010 between each calls.

On the given system, GetLocaleStr(GetThreadLocale, LOCALE_SSHORTDATE, 'm/d/yy') returns "dd-MM-yyyy" (The short date format for the current user)

The problem happens on WinXP SP3. (Though our application isn't used on any other OS version, can't say if it's specific to that version).

My initial thought is that it might be security-related (the user's security is air-tight), but I couldn't prove it yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆离笙 2024-10-09 14:55:41

可能的答案是用户的默认区域设置不是您的特定操作系统实例支持的 lcid。

解决方法很简单——只要不要使用丑陋的变体即可。尝试使用 DateTimeToString 代替。
PS 还有助于指定您的 Delphi 版本。

The likely answer is that the default locale for the user is not a supported lcid for your particular o/s instance.

The work-around is easy - just dont use ugly variants. Try DateTimeToString instead.
P.S. Also helps to specify your version of Delphi.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文