开发者

Creating an array with variables

I am relatively new to Delphi so please bear with me. B开发者_如何学JAVAasically, I need to set variables as different values based on whether or not I am testing in an English or French translated environment. All menus in these TC scripts are accessed by their names and in French they are not the same. I can, however, access them by their position in the menu - such as [4|2].

I have a list of constants and would like to set up an array to set MenuItem1 to either File|New or [4|2] depending on the value of tcDecimalSeparator <> '.' (set as a declared constant).

Does this make sense? What would be the easiest / best way to do this?

I know I could probably set this all up with data driven testing but I don't want to rework the scripts that much prior to release.


No, your proposed solution does not make sense. First, switching based on the current decimal separator is unreliable. Second, if you already know the positions of the menu items, and they always work, regardless of the program's language, then why mess around with the English menu captions at all? Just use the menu positions all the time. (Or, if you already have something set up to select the menu text based on the language, why not also use the French menu text instead of switching between English text and French positions?)

To do what you propose, you can set up a two-dimensional array of menu identifiers:

const
  TLanguage = (lEnglish, lFrench);
  TUIElement = (uiFileNew, uiFileOpen, ...);

  MenuIDs = array[TUIElement] of array[TLanguage] of string = (
    ('File|New', '[4|2]'),
    ('File|Open', '[4|3]')
  );

Then, when you want a string, select the item that corresponds to your UI element, and then select the string for the current language:

if tcDecimalSeparator = '.' then
  CurrentLang := lEnglish
else
  CurrentLang := lFrench;

UseMenuItem(MenuIDs[uiFileNew, CurrentLang]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜