Sunit Katkar's Home Page

 Palm Tutorial:



 Palm Links:
 

What did I understand?

First of all let me explain the concept (as I understand it, please correct me if I am wrong) of storing a single text record in the Palm OS.

Basically a record in Palm OS is a container to store one large text string. The Data Manager takes care of locking, releasing and deleting a record. What you have to do is fill in your text data in this record.

Strings

Now if you had one text field in your form it would be okay to store the entire string as one record. But what if your form had two or more text fields? In such a scenario, you would have to keep two separate strings in one big string.  For this you must store a collection of small strings which are null ('\0') terminated. 

Now, if you had two fields with the following sample text data:

Text Field 1:

S

u

n

i

t

 

K

a

t

k

a

r

Text Field 2:

l

o

v

e

s

 

P

i

n

k

 

F

l

o

y

d

Then to store them as one string, the final or packed string would look like this in the record :

S

u

n

i

t

 

K

a

t

k

a

r

\0

l

o

v

e

s

 

P

i

n

k

 

F

l

o

y

d

\0

So we must device a scheme to 'pack' two or more loose or unpacked strings into one big string.

Notice the null terminator '\0'. This is really helpful in our data retrieval routine to read a string upto a null terminator and populate a single element of the structure. And then read the next string till you get another null terminator and so on.

Structures

To store and handle individual strings from different text fields you must have a structure with elements for every field on your form. This way, it will be easy to assign the text entered by the users to each structure element and handle these structures. It means that you must have two structures - one to store all the 'unpacked' text  strings as separate elements and a temporary second one to store all these unapcked strings as one 'packed' string.

One more thing: We will decide at the onset about the maximum number of characters that a text field can hold. I have taken an arbitrary figure of 50 characters maximum. We need to do this so that our static structure will always have a fixed size in memory. Though dynamic memory allocation is possible, I decided against it and instead traded off by limiting my text fields to a certain length. Also, this structure is temporary. In the final record we will not be wasting any space as we will pack the strings one after the other.

GUI

You may already know this but, anyway, here goes...

For code maintenance and ease of modifications in the future, you need to separate the GUI code (mainly event handling) from the data structures that you will create. This way of code separation is also proven to be the ideal way (as in the Model-View-Controller and Microsoft's Document-View acrchitecture).

Our multi field form application will have the following general design:

  1. We will create a structure called MultiFieldFormDocumentType which will have elements to represent each field on the form.

  2. We will also write 'getters' and 'modifiers' like in Java or C++.

  3. This structure/document will be a static structure/document whose instance will live in the memory for the entire life of the application.

  4. We will write a function which will 'construct' the document. i.e. it will read from the record and fill in all the elements of the document.

  5. We will also write a Java like toString function which will serialize or write this structure of unpacked strings into a null terminated packed string.

  6. And offcourse other miscellaneous functions for setting the text field, getting a pointer to a GUI object, allocating space for the document and initialising it with a starting value, etc.

Maybe, my explanation is not very clear, but my source code is commented quite exhaustively. You can definitely find what I missed here in the source code.

Main |  1 |  2 |  3 |  4 |  5 |  6