Sign in to follow this  
andrewjfox

Grouped components

Recommended Posts

Do component events work when the component is inside (part of) a group of components?

I have several components that "listen" to messages and perform an action depending on data in message

In the OnLoad event sequence I use AddListener("my_message")

and in the OnMessage event the component checks Param1 & Param2 befoe performing some action

// OnLoad sequence 
? "Component Loaded: MyComponent"
CreateProperty("Status",0,"Misc","operating status","pzinteger")
AddListener("my_message")

//OnMessage sequence
? "Rcvd Message: " + strMessage
if ((Param1 == 0) && (NumRows(Param2) > 1))  
   Status = Param2[1]
endif

The Status property is then used by the OnPaint event to change the component attributes such as colour & blink status.

This all works perfectly until I group the component with other components into a "super-component" and it all stops working. Do I need to have the new super-component listening for the same message? Should the components inside the super-component be receiving the message?

Thanks

Share this post


Link to post
Share on other sites

No, it doesn't look like a message would pass through to a group member. The members of a group are encapsulated into the group essentially as private members. In general, if you are going to group things, you should put all the events in the group instead of the components of the group. One main reason for doing this is that you can then edit those events without having to disband the group every time.

But before you group the components, give each of the components you want to edit programmatically from the group a name. Now, normally to edit a property of a component, you'd do: component.componentName.property. Well, if a component is in a group, it can only be accessed programmatically from the group's events. There you only need componentName.property to access a particular component. This allows you to duplicate the group component (or make it into a user component) without having to worry about name conflicts.

So, you'd still use the messaging idea (presumably), but you'd have the group event's handle it instead of the specific component in the group. The group event would then change the properties of the contained component.

Share this post


Link to post
Share on other sites

That's what I was afraid of.

I have created and debugged/tested a small library of components to re-use, knowing I would not be able to edit once grouped. And since most of the grouped-components use many of the same base components this seemed the logical approach.

In fact the main reason the components are grouped is to allow them to be made visible/invisible as a single group rather than having to script through all components on a page and change each one. I'm essentially trying to mimic a tabbed page, using buttons to hide/show groups of components on each page, but in the same physical space.

If any better ideas on how to achieve this please let me know otherwise will redo events at group level.

As always, thanks for the help and quick reply

Share this post


Link to post
Share on other sites

Yes, there is a much easier way to do this: use overlaid pages. You can see this in action in the ashlandwater.ctl sample included in the DF download. Basically you'd create a page with just the tabs that change what is displayed, leaving a big blank area for the content of each tab. Then you'd create a page for each content, only using the area of the screen that the tabs are not displayed. Then, when you click on the tab, you'd change the page to two pages, the one with the tabs, and the content page. Something like:

page.strCurrentPage = "tabs, tab1"

page.strCurrentPage = "tabs, tab2"

etc.

This can be used with lots of different menu types, and in AshlandWater is used with a clickable map. Concept is the same though and there is no visible / invisible settings involved.

Share this post


Link to post
Share on other sites

Thanks for the info, I've had a bit of a play with this option but only appears to work with normal pages, whereas I'm trying to have tabbed areas within a popup window.

Nonetheless very handy to know for future reference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this