如何翻译在Delphi中声明为数组的字符串?

4

我们使用Delphi编写了应用程序,现在正在实现语言翻译功能。我们已经添加了核心代码以翻译ResourceString中声明的字符串,这部分已经很好地工作了。但是在数组中声明的字符串没有被翻译。

例如:

resourcestring
 Error_Text = 'Invalid Value'; 

这个工作正常。

Const
 ERROR_TYPE : Array[0..2] of String = ('Invalid Name', 'Invalid Age', 'Invalid Address');

如何将这些数组值添加到resourcestring中?
1个回答

6

我认为你无法直接拥有一个 resourcestring 数组,我会尝试使用函数来代替,类似于:

resourcestring
  ERROR_TYPE0 = 'Invalid Name';
  ERROR_TYPE1 = 'Invalid Age';
  ERROR_TYPE2 = 'Invalid Address';

type
  TMyIndexType = 0..2;

function ERROR_TYPE(AIndex: TMyIndexType): string;
begin
  case AIndex of
    0: Result := ERROR_TYPE0;
    1: Result := ERROR_TYPE1;
    2: Result := ERROR_TYPE2;
    else
      // appropriate error handling
  end;
end;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接