Real Software Forums
http://forums.realsoftware.com/

WebToolbar dynamic caption issue
http://forums.realsoftware.com/viewtopic.php?f=23&t=47769
Page 1 of 1

Author:  louisd [ Thu May 02, 2013 5:16 pm ]
Post subject:  WebToolbar dynamic caption issue

Hello all;

I am writing a web app that needs to be multi-lingual. TYhe strings are in a database, and upon loginm, I load the language-specific strings in an array setup as a session property. Then, each page gets assigned the appropriate strings in the Open event.

I am experiencing a problem with the WebToolbar. It resists my best efforts to set the menu item captions at runtime. My code is like this, in the M.Open event section:

(The page is called Mainmenu and the toolbar is currently called M, and each item is called M01, M02 etc.)

Dim item1 As WebToolbarContainer
item1 = WebToolbarContainer(Me.ItemWithName("M01"))
If item1 <> Nil Then
item1.Caption = session.apptext(3) 'Application menu
End If


This code compiles OK, but I always get an Unhandled IllegalCastException error. If I use for example "M00", which is not already set at design time, then the code runs just fine.

Can someone please point me in the direction of a solution? (or at least shed some light on my error)

Thanks in advance.

LD

Author:  taylor-design [ Thu May 02, 2013 6:07 pm ]
Post subject:  Re: WebToolbar dynamic caption issue

Stab in the dark: does the code work in the Shown event? In WE the page and controls are not fully setup in Open.

Author:  louisd [ Thu May 02, 2013 7:05 pm ]
Post subject:  Re: WebToolbar dynamic caption issue

I also tried in the shown event. Same issue.

I should also perhaps have indicated that I am using 2012 R2.

thanks.

LD

Author:  taylor-design [ Thu May 02, 2013 7:58 pm ]
Post subject:  Re: WebToolbar dynamic caption issue

Looking over the code...is M01 actually a WebToolbarContainer? The code works for me. But if I remove the container and add a button with the name M01, then it fails with an IllegalCastException.

If you have different types in your toolbar you will need to use IsA to check type and correctly cast each item. Example:

Dim item1 As WebToolbarItem
item1 = Me.ItemWithName("M01")

If item1 IsA WebToolbarContainer Then
WebToolbarContainer(item1).Caption = "Test"
ElseIf item1 Isa WebToolbarButton Then
WebToolbarButton(item1).Caption = "Test"
End If

Author:  louisd [ Thu May 02, 2013 8:09 pm ]
Post subject:  Re: WebToolbar dynamic caption issue

Doh!

I guess I overlooked the obvious. Thank you so much for your help!

LD

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/