The Origin Forum
File Exchange
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Prob. with enum as a parameter in a Command Window

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
theuser Posted - 07/07/2020 : 10:29:08 AM
Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:

Origin Pro 2017 (64 bit) SR 2; b9.4.2.380

Windows 10.

Hello everyone!

I have a problem with passing an enum instance to the function via Command window, where as if I call a separate function and do the same everything works as expected.

Here is the minimum working example and the output:


#include <Origin.h>

typedef enum {first, second,third} Numbers_type;
void Somesomefunc123456(Numbers_type num)
{
		switch (num)
	{
		case first: out_str("is 1");
			break;
		case second: out_str("is 2");
			break;
		default: out_str("somenum");
		
	}
	
}

void anotherfunc()
{

Somesomefunc123456(first);
}


Call stack + output:

9> Somesomefunc123456(first)
Command Error!
10> anotherfunc()
is 1
12> Somesomefunc123456(1)
is 2
13> Somesomefunc123456(0)
is 1



Why the direct call via enum does not work? I need enum names like first, second and not integers for the actions, that the function will perform on the whole project (multiple folders, subfolders etc.), so simply passing numbers is not a solution I am looking for

Thank you in advance
2   L A T E S T    R E P L I E S    (Newest First)
theuser Posted - 07/08/2020 : 02:56:31 AM
quote:
Originally posted by cpyang

Command Window is a LatTalk environment. OC enums are inside OC, not visible as LT variables.

We know of this limitation and we can improve it, but will need to be in a future version. I added JIRA ORG-22210 for this.

CP





Okay.

In case people will bump into this, I also tried #define and it did not work. Here is the possible workaround using "hashing" from string:


int Hash_testfunc54321(string command)
{
		if(command.CompareNoCase("Normalize")==0)return 0;
		else 
			{
				if(command.CompareNoCase("Rename")==0)return 1;
				else return 0xFFFF;
			}
	//Continue the Ladder for all the availiable commands
}


void maintestfunc12345(string command)
{
	switch(Hash_testfunc54321(command))
	{
	case 0: 
		out_str("it is Normalize");
		break;
	case 1: 
		out_str("it is Rename");
		break;
	//Continue for all the availiable commands
	default:
		out_str("something else");
		break;
	}
}


Labtalk call stack + output:

4> maintestfunc12345("Rename")
it is Rename
5> maintestfunc12345("Normalize")
it is Normalize
6> maintestfunc12345("Garbage")
something else


cpyang Posted - 07/07/2020 : 12:15:31 PM
Command Window is a LatTalk environment. OC enums are inside OC, not visible as LT variables.

We know of this limitation and we can improve it, but will need to be in a future version. I added JIRA ORG-22210 for this.

CP

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000