Menu item "Enabled When section" evaluate

Discussion forum about all things Team Developer 5.x and 6.x
e.russo
Italy
Posts: 38
Joined: 16 Feb 2018, 14:02
Location: Turin, Italy

Menu item "Enabled When section" evaluate

Post by e.russo » 26 Feb 2018, 14:31

Hi,
In my application I select menu item actions by WM_COMMAND message, but I can't evaluate "Enabled when section"
How to evaluate "Enable When Section" for menu item?
I attach a simple program.
Thanks in advance

Enrico
You do not have the required permissions to view the files attached to this post.

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Menu item "Enabled When section" evaluate

Post by Jeff Luther » 26 Feb 2018, 17:48

There is an CDK_IT_EnabledWhen constant in the CDK that can be used for this, Enrico. Are you familar with using the CDK? I have a Tutorial showing some of the CDK's functionality on my TD page in the samples section: http://www.jeffluther.net/TD/index.html#Code_Samples

Here's what I did in the attached zip:
>> read in my tutorial with v5.2
>> added TRUE to Enabled When for the form's menu. And added a comment.
>> save it into a copy of my CDK Tutorial zip and have attached it, called: CDKTutorial-demo-JL-display TRUE in form EnabledWhen.zip

Here's what you do:
>> save and unzip attachment
>> run my demo in anything from v5.2 on up.
>> click the form's radio button: CDK_App.EnumTopLevelWindows()
See that Enabled When for form's menu has 'TRUE' displayed. NOTE that the entire Enabled When string property included my comment. You could parse out the first token from the return of the SAL line to get Enabled When: <boolean> value

Code: Select all

oMenuItem.GetAttributeX( CDK_IT_EnabledWhen )
The CDK has the outline in a top/down hierarchy. To get a handle to the form's menu, see the code beginning with this line:

Code: Select all

Call CDK_App.GetTopLevelWindow( sAryTopLevelWindows[nWindow], oTLWindow )
and continuing

Code: Select all

Set nMenusTotal = oTLWindow.EnumChildObjectsByName( CDK_IT_NamedMenus, sAryMenus )

Call oTLWindow.GetChildObjectByName( CDK_IT_NamedMenus, sAryMenus[nMenu], oMenu )
and down to this line:

Code: Select all

Set sResults = sResults || AddTABIndents( 3 ) || 'Enabled When: ' || oMenu.GetAttributeX( CDK_IT_EnabledWhen ) || sCR
That should be enough for you to modify your demo to add accessing the 'Enabled When: ' (or any other) attribute using the CDK.
You do not have the required permissions to view the files attached to this post.
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Menu item "Enabled When section" evaluate

Post by Jeff Luther » 26 Feb 2018, 19:22

I realized that I did not answer your full question, as I only provided info. in my previous msg. in how to use the CDK to get the Boolean expression in a menu's Enabled When: property.

The next piece of the puzzle is how to evaluate what that Boolean's expression is. To do that you need to call SalCompileAndEvaluate() which can evaluate an expression and return details of it. See my attached demo. of this. The demo sets a global var TRUE and calls my function, displaying what the var's value is. Then sets it FALSE and eval's again.

Sample saved in v5.2. Put these 2 pieces together and you can parse the Boolean Expression, then evaluate whether it's currently T or F. In this case, though I added Case statements for all the possible return values for SalCompileAndEvaluate(), in fact I'm only evaluating and my local funct. is only returning a Boolean value.
You do not have the required permissions to view the files attached to this post.
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

e.russo
Italy
Posts: 38
Joined: 16 Feb 2018, 14:02
Location: Turin, Italy

Menu item "Enabled When section" evaluate

Post by e.russo » 27 Feb 2018, 10:23

I use CDK only in design time to create/modify code.
I did not never use CDK in Runtime ( I did not know the SalOutlineCurrent function!!!)

I try it. Thank you.

Enrico

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2069
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Menu item "Enabled When section" evaluate

Post by Jeff Luther » 27 Feb 2018, 16:59

You are welcome! Let us know how this works out for you, Enrico.

BTW, I thought of one other item to what I wrote yesterday: TD requires that it be able to find any variable(s) in the expression you pass in SalCompileAndEvaluate(). That is, that any variables are within scope. In my simple demo of using this function, I declared a global var. whose scope can be 'seen' anywhere within the app's code, so TD will be able to find that variable g_bEval.
Jeff Luther @ PC Design
Palm Springs, California
TD info. & samples: http://www.jeffluther.net/TD/

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests