Jump to content

Local vs Global ghandles


David Kibble

Recommended Posts

Hi Guys.

Could you please give me an official steer on the use of local GHandles. Your examples and Studio always generate global scope vars for all GHandles, but is there actually any problem in taking the approach of using local (within a function) GHandles for graphic entities which are transient and modal such as dialogue boxes? For example you could have a function;

showDialogBox(...)
{
  GHandle container;
  GHandle button1;
  GHandle button2;

etc etc
  gwinShow(container);

  <event loop waiting and processing modal events for button 1 and 2>

  gwinDestroy(container);
}

I prefer this style wise as it contains the variables and logic, reduces the sheer volume of global vars which you end up with on a large UI project and creates a more easily reusable component.

But - are there any negative side effects within uGFX of doing this? I ask because I'm getting some odd behavior now on a large UI where container hierarchies are not redrawn properly and before I start diving into my code, it occurred to me I should check the above pattern with you guys.

Thanks

Link to comment
Share on other sites

There is no problem with that - a ghandle is effectively just a void *. Just be aware that if you exit the function without destroying the window you have lost the pointer to the window. That may however be perfectly acceptable eg a label on a container. After creation there may be no future need to access the label seperately from its container.

Link to comment
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
×
×
  • Create New...