General design strategy

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
farengeti
Knows some wx things
Knows some wx things
Posts: 26
Joined: Thu Dec 16, 2004 2:11 am

General design strategy

Post by farengeti » Sun May 01, 2005 10:00 pm

I have a program where most of the dialogs are dynamic. For example the number of wxTextCtrls needed in a given dialog depends on the user's choices. To deal with this, I have been using an stl::vector like

vector< wxTextCtrl * > myTextCtrls

And I simply add each of the wxTextCtrls to the vector. Then when I need the values from the textCtrls, I iterate through the vector and GetValue() from each textCtrl. This seems like a very unelegant approach, and I was wondering what people thought the 'right way' to do this was. My thought:

1) Use validators and simply keep an array of wxStrings, then call TransferDataFromWindow(). However, sometimes I need to access the controls directly (for example to highlight an invalid input from the user), and in those cases, validators won't (I think) work.


Is there an easier or better way? Can I use XRC or XML do produce dynamic dialogs like this? Should I given that I've never used either before? What would you do?

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Mon May 02, 2005 6:47 am

I always favor for encapsulation by isolation.

For example, when the wxTextCtrl controls are maintained by a class e.g. EditManager you can add an array in there and define;

EditManager::Add, EditManager::Delete, and an interator to iterate through the controls to display by providing the parent window to display it on only. To get data back, also use this interface. The advantage is that you can change the wxTextCtrl to any other control without adjusting your code.

Then again I don't know much about your real problem area why this is needed, but encapsulation is never bad ;-)

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Post Reply