我正在使用 DevExpress ExpressEditors Library 6.45 中的 TcxDBImgage(适用于 Delphi 2009),并且此图像组件作为内置弹出菜单组件,其中包含菜单项“加载”、“保存”等。
我正在开发非英语语言的应用程序,我想覆盖这些菜单项的标题。
我检查了DevExpress Delphi代码,看看这些标题是如何加载的,代码是:
procedure RefreshCaptions;
begin
with FEditPopupMenu do
begin
Items[0].Caption := cxGetResourceString(@cxSMenuItemCaptionCut);
Items[1].Caption := cxGetResourceString(@cxSMenuItemCaptionCopy);
Items[2].Caption := cxGetResourceString(@cxSMenuItemCaptionPaste);
Items[3].Caption := cxGetResourceString(@cxSMenuItemCaptionDelete);
Items[5].Caption := cxGetResourceString(@cxSMenuItemCaptionLoad);
Items[6].Caption := cxGetResourceString(@cxSMenuItemCaptionSave);
end;
end;
function cxGetResourceString(AResString: TcxResourceStringID): string;
var
AIndex: Integer;
begin
AIndex := GetResOriginalStringIndex(AResString);
if AIndex <> -1 then
Result := FResStrings[AIndex]
else
Result := LoadResString(AResString);
end;
并且 dcr 文件(Delphi 编译器生成的文件)包含常量:
#define cxEditConsts_cxSMenuItemCaptionCut 64713
#define cxEditConsts_cxSMenuItemCaptionCopy 64714
#define cxEditConsts_cxSMenuItemCaptionPaste 64715
#define cxEditConsts_cxSMenuItemCaptionDelete 64716
#define cxEditConsts_cxSMenuItemCaptionLoad 64717
#define cxEditConsts_cxSMenuItemCaptionSave 64718
cxEditConsts_cxSMenuItemCaptionCut, "Cu&t"
cxEditConsts_cxSMenuItemCaptionCopy, "&Copy"
cxEditConsts_cxSMenuItemCaptionPaste, "&Paste"
cxEditConsts_cxSMenuItemCaptionDelete, "&Delete"
cxEditConsts_cxSMenuItemCaptionLoad, "&Load..."
cxEditConsts_cxSMenuItemCaptionSave, "Save &As..."
因此,这应该可以通过某种方式进行定制。可能的问题是 - 如何在使用 TcxDBImage 组件的项目的 Delphi 代码中覆盖这些常量?
我应该以某种方式重新定义资源字符串吗?我应该使用 STRINGS 表创建 *.res 文件吗?我检查了我的项目和 DevExpress 组件的 res 文件(例如,使用 Visual Studio 作为 res 文件的编辑器),它们仅包含图标和版本,没有字符串表。
我知道文档https://docs.devexpress.com/VCL/154039/ExpressCrossPlatformLibrary/how-to/localize-an-application和https://docs.devexpress.com/VCL/154011/ ExpressCrossPlatformLibrary/concepts/localizer-editor-ui,但我没有 Localizer 编辑器,我不确定最近的文档是否可以应用于我的 DevExpress 组件版本。
创建一个如下单元并将其包含在项目中某处的uses子句中。 当然,你也可以用同样的方法更改其他单位的资源字符串。
unit MxDxLocalization;
interface
implementation
uses
dxCore, cxClasses, cxEditConsts; // cxGridStrs, cxGridPopupMenuConsts, cxFilterConsts, ...
initialization
// replace ... with the desired caption
// cxEditConsts:
cxSetResourceString(@cxSMenuItemCaptionCut, '...');
cxSetResourceString(@cxSMenuItemCaptionCopy, '...');
cxSetResourceString(@cxSMenuItemCaptionPaste, '...');
cxSetResourceString(@cxSMenuItemCaptionDelete, '...');
cxSetResourceString(@cxSMenuItemCaptionLoad, '...');
cxSetResourceString(@cxSMenuItemCaptionSave, '...');
// ...
end.