tags:

views:

52

answers:

3

I never tried to do a GUI without a GUI designer and now I'm learning how to develop Palm OS applications with the book Palm OS Programming: The Developers Guide. And on it I have this code that is a declaration of some GUI items:

#define HelloWorldForm 1000
#define HelloWorldButtonButton 1003
#define HelloWorldMenuBar 1000

#define GoodnightMoonAlert 1101

#define FirstBeep 1010

#define SecondBeepmore 1000

I want to know some things:

  • I need to do this in a type of order?
  • Why I need to declare this numbers?
  • In what they are going to help me?
  • They have anything connected to the type of item they are?
+3  A: 

Those are probably "human readable shortcuts" (in the form of C macros it seems) associated with GUI elements: the said elements are probably only referenced through integers in the host system. You didn't provide us with much details to work with here.

The advantage of such technique is usually associated with easier maintenance (amongst others).

jldupont
+3  A: 

They resource IDs. You aren't required to define such macros, but if you don't, you'll instead have to use the raw integer values when you try to refer to the UI widgets in code. For example, the typical way you'd get a pointer to a UI control would be to call:

FormType* formP = FrmGetActiveForm();
UInt16 index = FrmGetObjectIndex(formP, objectID);
ControlType* controlP = FrmGetObjectPtr(formP, index);

You'd need to get pointers to the UI widgets in order to do things such as reading their states (such as for checkboxes), changing text labels, showing or hiding them dynamically, etc.

There's no type safety between the resource IDs and what you do with the pointer you get back from FrmGetObjectPtr; it's your responsibility to keep track of which ID corresponds to which type of control (the common practice is to use descriptive names).

jamesdlin
+1  A: 

They provide a couple of benefits.

  1. Documenting the code. Would you rather have a call like LoadForm(1000); or LoadForm(HelloWorldForm); in your source code?
  2. They may actually be used by the file that defines the resources. If you ever need to renumber the resources (perhaps you are merging two projects that both used 1000 for different forms), you would only need to modify the value in a single place.
R Samuel Klatchko