Structured Array Short Hand

I used structured arrays a lot! No I mean A LOT!

In fact, I generally have a class called FixedLookups that contains several Hardcoded Structured Arrays for things that are necessarily user configurable, but still easier for me to code a combo box using a structured array instead of hardcoding into control properties via the IDE.

That Class has a common Structure:

2014-09-22_0744

And then a number of arrays declared based on that structure, like this:

2014-09-22_0745

Then in the Constructor for the class I have code like this to populate the array.

2014-09-22_0748

Well it recently occurred to be, that WX allows you to specify an entire Array as one parameter using a “special” short hand code, by surrounding it with [].

So now those 8 lines of code, get replaced by 2 lines of code.

2014-09-22_0751

Much cleaner and easier to read. Obviously I wouldn’t use this for a complex array with a lot of fields, but very handy for this simple 2 field array.

Now, back to your regular schedule program….

9 thoughts on “Structured Array Short Hand

  1. Just a reminder if you are going to use the:
    ArrayAdd(arrDelimiter,[“,”,”Comma (,)”])
    and you have a few declared variables within the strLookup, then you must declared the values in the ArrayAdd in order of how you declared the variables in the strLookup structure.

    The reason for pointing this out is, if you change the order of any of the variables in the strLookup structure.You then need to hunt down all the places that you used this method, which is a draw back, as the IDE does not pick it up.

    So if you use the “many lines” method you will not have this problem, as it will automatically be correct if the names of the variables did not change. And if it did change, then the IDE will pick it up nicely for you.

    Like Uncle Pete says, it is very handy for a very few variables in a structure..

    Like

  2. hi,

    I just happened to stumble upon your site.
    I’m from Canada and didn’t know there were some Wx developpers in the US with blogs like this.
    Thanks to Google … now I know!

    If you don’t mind my “intrusion”, let met suggest another possible simplification 🙂
    Some of you might like this.

    seeya 🙂
    barnacker

    Like

  3. hi,
    I just happened to stumble upon your site.
    I’m from Canada and didn’t know there were some Wx developpers in the US with blogs like this.
    Thanks to Google … now I know!

    If you don’t mind my “intrusion”, let met suggest another possible simplification 🙂
    Some of you might like this. (see picture)

    seeya 🙂
    barnacker

    Like

    1. Barnacker, we have a Google+ community “WxLIVE – US”

      We also have a Skype chat group, contact me via skype (PeteHalsted) and I can add you to the skype group if you like

      Like

  4. Good morning, I’m using a structured array to store information, but everytime I add some values with arrayaddline, it adds them and then deletes it, so my array is always empty. What can I do to solve this?

    Like

    1. I rarely use ArrayAddLine with a structured array, and would have to see your code to know specifically what they issue might be.

      Generally with a structured array I would do something like:

      MyStructure is structure
      Field1 is int
      Field2 is string
      END

      MyRecord is MyStructure
      MyArray is array of MyStructure

      MyRecord.Field1 = 1
      MyRecord.Field2 = “XYZ”
      ArrayAdd(MyArray,MyRecord)

      ArrayAddLine would would be like this instead:
      ArrayAddLine(MyArray,1,”XYZ”)

      BTW, this is the type of issue that we created WXperts.com for. If you are having a specific issue with some code in your project/application, per incident support can get you help and an answer quickly and getting you moving forward with your project.

      Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s