Want to reduce sourcecode for "Setting Variables Of Type Structure"

 

Hi,

here's an example of my Question/Problem?

Lets define the following structure ... 

struct DP_ButtonRecord { int DP_SetupNumber; string DP_SetupName; int DP_ButtonNumber; .....

The variable for the Structure is definied as a an array of 10 Elements.

DP_ButtonRecord  DP_Button[10];

Normaly, we have to define variables like ( index=i), like this:

DP_Button[i]. DP_SetupNumber=1;

DP_Button[i]. DP_SetupName = "Hallo World";

DP_Button[i]. DP_ButtonNumber=i;

Is there any posibility to take access on the variables without always writing DP_Button[i], to define like this example?

with (DP_Button[i]) do {  DP_SetupNumber=1; DP_SetupName = "Hallo World";  DP_ButtonNumber=i; }

If yes, please let me know how.

If NO, this feature would be very helpful for reducing Programcode and make it clearer.

Thanks al lot for all hints, you let me know about my Question.

Alex

 
  1. Alexander Hoch: Normaly, we have to define variables like ( index=i), like this:

    DP_Button[i]. DP_SetupNumber=1;

    DP_Button[i]. DP_SetupName = "Hallo World";

    DP_Button[i]. DP_ButtonNumber=i;

    Just define an initiator.

    Struct DP_ButtonRecord {
       void init(int sn, string n, int bn){
          DP_SetupNumber=sn; DP_SetupName = n; DP_ButtonNumber=bn; }
       ⋮
    }; // DP_ButtonRecord 
    DP_Button[x].init(1, "Hallo World", i); 
  2. Alexander Hoch: Is there any posibility to take access on the variables without always writing DP_Button[i], to define like this example?

    with (DP_Button[i]) do {  DP_SetupNumber=1; DP_SetupName = "Hallo World";  DP_ButtonNumber=i; }

    Define a default constructor
    Struct DP_ButtonRecord {
       DP_ButtonRecord() : DP_SetupNumber(1), DP_SetupName("Hallo World"), DP_ButtonNumber(i){} //[cTor]