107 views
in Embedded Wizard Studio by
Hello Embedded Wizard,

I am using EW 13.02.

I Have a function that tries to combine a error message string. It uses an array of active message id's, finds the corresponding string and either returns an empty string, a string with one message, or a string like "1/3: mess 1   2/3: mess 2   3/2: mess 3"

In this function I use a do ... while (false) construction with a strange result (again)

string GetMessageString()

var string   sXOfYSeparator      = "/";
var string   sNrMessageSeparator = ": ";
var string   sMessageSeparator   = "   ";

array string asShownMessages[3];
var int32    iShownCount = 0;
var int32    iMessageIndex;
var int32    iShownIndex;
var string   sShownMessage;

do
{
  if (false == MessagesChanged) // class property (boolean)
  {
    break;
  }

  CurrentMessage = "";   // class property (string)
  MessagesChanged = false;

  // 1st: Get max < asShownMessages.size> unique messages
  for(iMessageIndex = 0; iMessageIndex < NrOfMessages; iMessageIndex++)
  {
    var bool bFound = false;
    sShownMessage = Application::TheSettings.GetFaultText(Messages[iMessageIndex]); // convert id to string from string table
    for(iShownIndex = 0; iShownIndex < iShownCount; iShownIndex++)
    {
      if (asShownMessages[iShownIndex] == sShownMessage)
      {
        bFound = true;
      }
    }
    if (false == bFound)
    {
      asShownMessages[iShownCount] = sShownMessage;
      iShownCount++;
    }
    if(iShownCount == asShownMessages.size)
    {
      break;
    }
  }

  // 2nd: Create Message string

  switch(iShownCount)
  {
    case 0: CurrentMessage = "";
    case 1: CurrentMessage = asShownMessages[0];
    default:
    {
      sShownMessage = "";
      for(iShownIndex = 0; iShownIndex < iShownCount; iShownIndex++)
      {
        if (iShownIndex != 0) sShownMessage = sShownMessage + sMessageSeparator;
        sShownMessage = sShownMessage + string(iShownIndex + 1) + sXOfYSeparator + string(iShownCount) + sNrMessageSeparator + asShownMessages[iShownIndex];
      }
      CurrentMessage = sShownMessage;
    }
  }
} while(false);

return CurrentMessage;
 

 

====================== End of code

Generated code

/* 'C' function for method : 'Application::MessageCollection.GetMessageString()' */

XString ApplicationMessageCollection_GetMessageString( ApplicationMessageCollection _this )
{

  XString asShownMessages[ 3 ] = {0};

  XInt32 iShownCount = 0;

  XInt32 iMessageIndex;

  XInt32 iShownIndex;

  XString sShownMessage;

 

  for (;;)

  {

    if ( 0 == _this->MessagesChanged )

      break;

 

    ApplicationMessageCollection_OnSetCurrentMessage( _this, 0 );

    ApplicationMessageCollection_OnSetMessagesChanged( _this, 0 );

  // 1st: Get max < asShownMessages.size> unique messages
    for ( iMessageIndex = 0; iMessageIndex < _this->NrOfMessages; iMessageIndex++ )

    {

      XBool bFound = 0;

      sShownMessage = ApplicationSettings_GetFaultText( EwGetAutoObject( &ApplicationTheSettings,

      ApplicationSettings ), _this->Messages[ EwCheckIndex( iMessageIndex, 10 )]);

 

      for ( iShownIndex = 0; iShownIndex < iShownCount; iShownIndex++ )

        if ( !EwCompString( asShownMessages[ EwCheckIndex( iShownIndex, 3 )], sShownMessage ))

          bFound = 1;

 

      if ( 0 == bFound )

      {

        asShownMessages[ EwCheckIndex( iShownCount, 3 )] = sShownMessage;

        iShownCount++;

      }

 

      if ( iShownCount == 3 )

        break;

    }

  // 2nd: Create Message string

    _EXIT_LOOP_2:    //  <<  THIS LABEL SHOULD NOT BE GENERATED

 

    switch ( iShownCount )

    {

      case 0 :

        ApplicationMessageCollection_OnSetCurrentMessage( _this, 0 );

      break;

 

      case 1 :

        ApplicationMessageCollection_OnSetCurrentMessage( _this, asShownMessages[

        0 ]);

      break;

 

      default :

      {

        sShownMessage = 0;

 

        for ( iShownIndex = 0; iShownIndex < iShownCount; iShownIndex++ )

        {

          if ( iShownIndex != 0 )

            sShownMessage = EwConcatString( sShownMessage, EwLoadString( &_Const00D9 ));

 

          sShownMessage = EwConcatString( EwConcatString( EwConcatString( EwConcatString(

          EwConcatString( sShownMessage, EwNewStringInt( iShownIndex + 1, 0, 10 )),

          EwLoadString( &_Const00DA )), EwNewStringInt( iShownCount, 0, 10 )), EwLoadString(

          &_Const00DB )), asShownMessages[ EwCheckIndex( iShownIndex, 3 )]);

        }

 

        ApplicationMessageCollection_OnSetCurrentMessage( _this, sShownMessage );

      }

    }

 

    goto _EXIT_LOOP_2; //  <<  THIS LABEL SHOULD NOT BE CALLED

  }

 

  return _this->CurrentMessage;

}

1 Answer

0 votes
by

Hello Karijn Wessing,

thank you very much for reporting us this error case. I was able to reproduce it. It seems the issue appears when combining do-while(false) and the switch-case embedded inside it. Replacing switch-case by a cascade of if-else statements seemed to work. Can you use if-else in this case as workaround? We have to investigate the issue more in detail and will provide a fix for it in the next version.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...