I had problems using the wxArray class. I got some hints via the C++ programming forum (http://forums.wxwidgets.org/viewtopic.php?t=3483). That was enough to try it out myself.
Here's what I've done:
- Created a structure:
Code: Select all
typedef struct { wxString ComponentName; wxString ComponentDir; wxString SubsystemName; wxString RootName; size_t LevelComponentName; size_t LevelComponentDir; size_t LevelSubsystemName; size_t LevelRootName; } ComponentDefinition;
- Used the macro (see documentation) to instantiate an array where I will put pointers to my structure.
This is in fact a new ADT, with CDefArray as name (just like int, char,...)Code: Select all
WX_DEFINE_ARRAY_PTR( ComponentDefinition *, CDefArray );
- Created a variable of the type CDefArray:
This is all done in the header file, but I guess you can do this also in the cpp file.Code: Select all
CDefArray CompDefinitionArray;
- In my C-file function, I used it as follows:
I first add a new 'instance' of the structure, by giving it as a parameter to the Add function of the wxArray class. In fact, you create memory for the structure at that time and you pass the address to the Add function (just like defined in the prototype).Code: Select all
CompDefinitionArray.Add( new ComponentDefinition ); ComponentDefinition* test = CompDefinitionArray.Item( Counter );
Then I created a local pointer pointing to such structure and assigned it the value of one of the pointers located in the wxArray (indicated by a number: Counter).
At that moment, you can access the piece of memory that has been assigned for the structure which is pointed to by the returned pointer from the wxArray, or now by the pointer variable 'test', if you like. - From then onwards, it's not difficult anymore to access the fields of the structure.
It's done as follows:
The field RootName of the structure ComponentDefinition is a wxString type and I simply assign it a substring.Code: Select all
test->RootName = TempString.Mid( 0, EndPos );
This way, you can access all the fields of the structure you defined.
Retrieving information is equally simple. If you want to see if the content of the array (in fact, all the locations where the pointers in the array are pointing at) is correct, you can use something like this (here, I didn't recall the integers which are part of the structure, only the string fields):
Code: Select all
for ( size_t Counter = 0; Counter < NrOfElements; Counter++ ) { ComponentDefinition* test = CompDefinitionArray.Item( Counter ); LOGTEXT( _T( test->RootName + "\\" + test->SubsystemName + "\\" + test->ComponentDir + "\\" + test->ComponentName + "\n" ) ); }
Best rgds,
--Geert