如何在Delphi中调用EnumSystemLocales? [英] How to call EnumSystemLocales in Delphi?

查看:277
本文介绍了如何在Delphi中调用EnumSystemLocales?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用 EnumSystemLocales 在Delphi中。 例如:

{ Called for each supported locale. }
function LocalesCallback(Name: PChar): BOOL; stdcall;
begin
   OutputDebugString(Name);
   Result := Bool(1); //True
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   EnumSystemLocales(@LocalesCallback, LCID_SUPPORTED);
end;

问题是回调只被调用一次。

The problem is that the callback is only being called once.

注意: EnumSystemLocales 返回true,表示

Note: EnumSystemLocales is returning true, indicating success.

EnumSystemLocales 的言论表示我的回调必须返回 true 才能继续枚举(或更正确的是,不能返回 false 继续枚举):

The remarks of EnumSystemLocales says that my callback must return true to continue enumerating (or more correctly, must not return false to continue enumerating):


该函数通过传递枚举语言环境指定应用程序定义的回调函数的区域设置标识符,一个位于
a时间。这个
继续,直到所有已安装或支持的区域设置标识符
已传递给回调函数或回调函数
返回FALSE。

The function enumerates locales by passing locale identifiers, one at a time, to the specified application-defined callback function. This continues until all of the installed or supported locale identifiers have been passed to the callback function or the callback function returns FALSE.

回调函数的文档

BOOL CALLBACK EnumLocalesProc(
  __in  LPTSTR lpLocaleString
);

一个评论者遇到了不为false的定义的问题:

a commenter has come across a problem with the definition of "not false":


此函数必须返回1,而不是(DWORD)-1才能继续处理

This function must return 1, not (DWORD) -1 to continue processing

这使我认为delphi的定义

This makes me think that delphi's definition of

True: BOOL;

与Window不同。 (这就是为什么我尝试了一个返回值 BOOL(1) - 仍然失败)。

is different than Window's. (That's why i tried a return value of BOOL(1) - which still fails).

接下来我想知道如果它甚至不应该是 stdcall

Next i wonder if it's not even supposed to be stdcall.

无论哪种方式,有人可以建议如何在Delpi中调用 EnumSystemLocales

Either way, can someone suggest how, in Delpi, to call EnumSystemLocales?

修改:还试过:


  • 结果:= BOOL(-1);

  • 结果:= BOOL($ FFFFFFFF) ;

  • 结果:= BOOL(1);

  • 结果:= True;

  • Result := BOOL(-1);
  • Result := BOOL($FFFFFFFF);
  • Result := BOOL(1);
  • Result := True;

推荐答案

p>尝试声明 LocalesCallback 这样的功能

try declarating the LocalesCallback function like this

function LocalesCallback(Name: PChar): Integer; stdcall;

查看此示例

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Windows,
  SysUtils;

function LocalesCallback(Name: PChar): Integer; stdcall;
begin
   Writeln(Name);
   Result := 1;
end;

begin
  try
    EnumSystemLocales(@LocalesCallback, LCID_SUPPORTED);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

这篇关于如何在Delphi中调用EnumSystemLocales?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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