-2

depending on two variables I want to display different text boxes in a template generator which I assume is based on Delphi.

Selection of the text box will be depending of the receivers country (AVX['M_COUNTRYC']) and article category (artcategory). There are at least 4 categories named 'Lizenz', 'Digifit', 'Hardware' and 'Accessories'.

I wanted to generate the following outcome:

  • OPTION 1: Country is D --> Default text box (DBMemoSchlusstext) appears
  • OPTION 2: Country is not D and not CH and at least one of the items categories is Hardware or Accessories --> Textbox HardEU appears
  • OPTION 3: Country is not D and none of the items has category Hardware or Accessories --> Textbox LizNotDE appears
  • OPTION 4: Country is not D but CH and at least one of the items categories is Hardware or Accessories --> Textbox HardNotEU appears

I already tried different approaches but none of them work:

Approach 1:

if not (AVX['M_COUNTRYC'] = 'D') then begin
   if (AVX['M_COUNTRYC'] = 'CH') and (AVX['P_ARTCATEGORY'] = 'Lizenz') or (AVX['P_ARTCATEGORY'] = 'DIGIFIT') then begin
      DBMemoSchlusstext.visible := false;
      LizNotDE.visible := true;
   end
   else if (AVX['M_COUNTRYC'] = 'CH') and (AVX['P_ARTCATEGORY'] <> 'Lizenz') and (AVX['P_ARTCATEGORY'] <> 'DIGIFIT') then begin
      DBMemoSchlusstext.visible := false;
      HardNotEU.visible := true;
   end
   else if (AVX['M_COUNTRYC'] <> 'CH') and (AVX['P_ARTCATEGORY'] = 'Lizenz') or (AVX['P_ARTCATEGORY'] = 'DIGIFIT') then begin
      DBMemoSchlusstext.visible := false;
      LizNotDE.visible := true;
   end
   else if (AVX['M_COUNTRYC'] <> 'CH') and (AVX['P_ARTCATEGORY'] <> 'Lizenz') and (AVX['P_ARTCATEGORY'] <> 'DIGIFIT') then begin
      DBMemoSchlusstext.visible := false;
      HardEU.visible := true;
   end;
end else begin
   DBMemoSchlusstext.visible := true;
end;
end;

Approach 2:

if (AVX['M_COUNTRYC'] = 'D') then DBMemoSchlusstext.visible := true;
else if (AVX['P_ARTCATEGORY'] = 'Lizenz') and (AVX['P_ARTCATEGORY'] <> 'Hardware') then LizNotDE.visible := true;
    else if (AVX['M_COUNTRYC'] = 'CH') then HardNotEU.visible := true;
        else HardEU.visible := true;
end;

Thanks in advance for any tips or recommendations

Timo
  • 1
  • 2
  • 1
    The second approach will not compile because of the `;` before the first `else`. Sae for the second and third `else`. – MartynA Feb 06 '19 at 21:13
  • You can read also [this answer.](https://stackoverflow.com/a/32933320/5043424) – asd-tm Feb 07 '19 at 06:53

2 Answers2

3

For better understanding I use short variables for the conditions and output, so you have to replace those with the actual code items:

var
  option: 1..4;
begin
  if isD then option := 1
  else if isHardware or isAccessories then
    if isCH then option := 4
    else option := 2
  else option := 3;

  Default := (option = 1);
  HardEU := (option = 2);
  LizNotDE := (option = 3);
  HardNotEU := (option = 4);
end;
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • Thank you. Unfortunately the program seems not to accept the code (i replaced the variables as you mentioned). It shows a message like type expected, var found. – Timo Feb 07 '19 at 13:32
0

Thank you all for your help. This is the new code:

DBMemoSchlusstext.visible := false;
HardNotEU.visible := false;
HardEU.visible := false;
LizNotDE.visible := false;

if (AVX['M_COUNTRYC'] = 'D') then begin DBMemoSchlusstext.visible := true; end
else if ((AVX['P_ARTCATEGORY'] = 'Smartfit Hardware') or (AVX['P_ARTCATEGORY'] = 'Smartfit Zubehör')) then begin
    if (AVX['M_COUNTRYC'] = 'CH') then begin HardNotEU.visible := true; end
    else begin HardEU.visible := true; end
else begin LizNotDE.visible := true; end;
end;

It seems not to be completely wrong but the last statement else begin LizNotDE.visible := true; end; is never be shown. I'm not completely sure about the parentheses and semicolons.

Further the program used only seems to consider the last article in the article listing.

Timo
  • 1
  • 2
  • The last else part should be executed when the conditions for Option 3 are satisfied. Perhaps your test data doesn't cover that case? – Uwe Raabe Feb 07 '19 at 14:24