To use a structure first define the structure...
- Code:
#define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}
A single instance of the structure is declared...
- Code:
struct(ControlInfo$, ControlStruct);
then filled with data...
- Code:
Fill(ControlInfo$, "Form", "FORM", 0, "WS_TABSTOP|WS_VISIBLE");
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:
#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;
In order to improve readability and take a few lines out of the code I chose to use a small helper procedure.
- Code:
#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;
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.