Register
Site Login
Site Search
Forums
Advertisement
Welcome to PocketMatrix. PocketMatrix is dedicated to providing the best online community for mobile device developers and enthusiests. What's new?

Need help with an FAQ


Need help with an FAQ

Postby kornalius » Dec 13, 2004 @ 6:56pm

Hi,

I am starting work on an FAQ on the PPL official's web site and I would like you guys to contribute with tips and tricks you have learnt from PPL over the last few months.

I plan on having different sections like:

Arrays
List
Structures
Matrix
GameAPI
...

Please post your question and answer here, I will add them to the site.

You can take a look at the early work I did already:

http://ppl.arwen.com/FAQ/
Regards,
Kornalius
President
ArianeSoft Inc.
http://www.arianesoft.ca
User avatar
kornalius
pm Member
 
Posts: 1704
Joined: Dec 9, 2003 @ 6:04pm
Location: Montreal, Québec, Canada


How to make a list of structures.

Postby bmanske » Dec 15, 2004 @ 9:06pm

To use a structure first define the structure...
Code: Select all

#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

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

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









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









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.
bmanske
pm Member
 
Posts: 117
Joined: Aug 26, 2004 @ 9:51pm


Return to Pocket Programming Language (PPL)


Sort


Forum Description

Discuss this new development tool.

Moderator:

kornalius

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron