To use a structure first define the structure...
- Code: Select all
1
| #define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}
|
| 1 lines; 1 keywds; 0 nums; 5 ops; 4 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
A single instance of the structure is declared...
- Code: Select all
1
| struct(ControlInfo$, ControlStruct);
|
| 1 lines; 1 keywds; 0 nums; 4 ops; 0 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
then filled with data...
- Code: Select all
1
| Fill(ControlInfo$, "Form", "FORM", 0, "WS_TABSTOP|WS_VISIBLE");
|
| 1 lines; 0 keywds; 1 nums; 7 ops; 3 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
Now, if you want a list of these structures, the declaration of the struct must happen for each element in the list. Here is an example...
- Code: Select all
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}
proc InitCtlInfo global(ControlInfo$); list(ControlInfo$);
add(ControlInfo$); struct(ControlInfo$, ControlStruct); Fill(ControlInfo$, "Form", "FORM", 0, "WS_TABSTOP|WS_VISIBLE");
add(ControlInfo$); struct(ControlInfo$, ControlStruct); Fill(ControlInfo$, "Button", "BUTTON", 1, "WS_TABSTOP|WS_VISIBLE");
add(ControlInfo$); struct(ControlInfo$, ControlStruct); Fill(ControlInfo$, "CheckBox", "BUTTON", 2, "WS_TABSTOP|WS_VISIBLE"); end;
proc main InitCtlInfo; goto(ControlInfo$, 0); ShowMessage(@ControlInfo.CtlType$, ",", ControlInfo.CtlIndex$ ",", Count(ControlInfo$)); end;
|
| 25 lines; 6 keywds; 4 nums; 70 ops; 15 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
In order to improve readability and take a few lines out of the code I chose to use a small helper procedure.
- Code: Select all
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}
proc FillCtlInfo(a1$, a2$, a3$, a4$) add(ControlInfo$); struct(ControlInfo$, ControlStruct); ControlInfo.CtlType$ = a1$; ControlInfo.CtlClass$ = a2$; ControlInfo.CtlIndex$ = a3$; ControlInfo.CtlDefStyle$ = a4$; end;
proc InitCtlInfo list(ControlInfo$); struct(ControlInfo$, ControlStruct); FillCtlInfo("Form", "FORM", 0, "WS_VISIBLE|WS_BORDER"); FillCtlInfo("Button", "BUTTON", 1, "WS_VISIBLE|WS_TABSTOP"); FillCtlInfo("CheckBox", "BUTTON", 2, "WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX"); end;
proc main InitCtlInfo; goto(ControlInfo$, 0); ShowMessage(@ControlInfo.CtlType$, ",", ControlInfo.CtlIndex$ ",", Count(ControlInfo$)); end;
|
| 25 lines; 5 keywds; 4 nums; 72 ops; 15 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
The thing to remember here is that an element in a list always has to be type cast as a structure after it is created.
B.