Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Pointer on Labels defined in lay.h
Re: Pointer on Labels defined in lay.h [message #42130 is a reply to message #42129] Sat, 22 February 2014 23:01 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1094
Registered: August 2007
Senior Contributor
Hello Yeti,

First of all, never allocate any ctrl object (or, for that matter any object) from the heap. Just avoid new and delete unless it is necessary. Use pointers only to point objects, not for memory management. Get yourself familiar with the core types and NTL containers, such as arrays and vectors, they are your best friend (and they will handle memory de/allocations, most of the time). Just read the docs, both api and other. They are straightforward and easy to understand. Once you use the ntl containers, you will never want to do otherwise.Smile

There are several ways you could achieve what you ask. But the easiest possible solution that comes to my mind now is using a ParentCtrl to represent a row (as far as I understand, a row in your code is a visual representation of a players' variables). So my suggestion would be:

1) Create a class that represents a row (name it whatever you like, a player, etc). It is pretty straightforward.

2) Add a layout to it (and add the children (buttons, labels, etc.) of the parent ctrl (a "Row") in the layout editor).

3) Since you now have a row class, in your main windows layout, add Row as custom ctrls. In layout editor -> Press right mouse button -> add a "Custom Class" and then set the custom class name (Row) and its ID (row1, row2, etc...)

4) done.

This way, your code will be much less cluttered and more logical, and readable.
I attached the source code of an example that contains three rows (each with a label and two buttons). The example code does nothing fancy but I hope it will give you the idea, so please take your time and examine it.

Ps. A better approach, if you'd have a lot of rows, say, 20, would be to use Arrays (eg., Array<Row> ... ). But it's another story. Wink

Regards.


[Updated on: Sat, 22 February 2014 23:26]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Dynamic Libraries __declspec(dllexport)
Next Topic: Problem when growing a vector
Goto Forum:
  


Current Time: Mon May 13 10:55:12 CEST 2024

Total time taken to generate the page: 0.02474 seconds