Professional Documents
Culture Documents
By LeRoy Olson
Written By
LeRoy T Olson
leroy157@comcast.net
February 11 2004
Index
About this booklet ———————————————————— Page 4
About Palmphi——————————————————————Page 4
The Future of this Booklet —————————————–———–Page 4
Introduction ———————————————————–———Page 5
Files Needed to use Palmphi, and Pose the emulator ——–———— Page 6
Chapter 1 Setup
Windows Installation of the Environment installer (11 Mb).————–Page 6
Installing Palmphi. —————————————————— Page 7
Installing Pose and support files. ——————————– Page 7
Configuring your Computer for Palmphi and Pose. ———–————Page 8
Windows XP configuration———————–————–—————Page 8
Windows 98 & ME configuration ———–——————————–Page 9
Common Problems ————————–———————————–Page 9
Using RegEdit ————————————–————————— Page 9
Chapter 2 Using Palmphi
Creating a Shortcut on the Desktop for Palmphi and Starting Palmphi—Page 11
First Program —————————————————–————– Page 13
Example 1 Using the Edit Box with Float and strings ——–———– Page 16
Example 2 Float to String, String Manipulation —————–———Page 18
Example 3 Working with Char, String Manipulation, Adding an Icon. Page 20
Example 4 Creating a Data Base Similar to Memo ——————— Page 24
Example 5 Using the values returned from Alert Message For
Controlling a Program ————————— Page 29
About This Booklet
This booklet was written for the person new to Palm application programming with at
least a limited knowledge of the C programming language to help understand some of the code
conventions used in this booklet. I have included a lot of images, and detailed descriptions
for each step of writing a program starting with, Creating a Project, Inserting objects into the
form, Writing the code, and Compiling into a new program with the Palmphi Visual Designer,
If you have any problems with usi ng or understanding sections of this booklet please let me
know so I can make the necessary changes.
All the code in this booklet was written with Palmphi Versions 1.52 through Version
1.62 . The executable programs or PRC ‘s have been tested and work properly using Pose the
Palm Emulator set up to emulate the Palm Pilot Pro with 2 Meg of memory, and version 3.3 of
the Palm OS Software.
My operating system is Windows XP Professional on a 1 Ghz Pentium, I also have it
setup on my old Pentium 100 Mhz laptop with Windows 98, and a 800Mhz Pentium with Wi n-
dows Me. They all were relatively easy to set up with some changes to the Registry in XP, and
Autoexec.bat in Win98, and ME. Setting up Palmphi for XP, 98, and Me will also be discussed
in this booklet.
The Future of this Booklet
I will be creating more application’s and documentation for using Palmphi to create
Palm Applications, such as separate source files to include in a project, Working with Menus,
the Ttable object, Beaming, and Syncing to a computer.
More information on the Palmphi Data Base which I believe can be used to access
more than one Data Base at a time, and update data simultaneously in more than one Data
Base.
Also I have chosen to use Euphoria ( A basic type language for Windows or Linux ) to
write applications for viewing and editing data on your Desktop Computer for use in your
Palm. The Euphoria site is://www.rapideuphoria.com/.
About Palmphi
These are excerpts from Palmphi home page.
Palmphi is a Windows desktop tool for visual design and Palm OS code generation.
The main features are
• WYSIWYG.
• Visual design
• Object inspector for controls and forms, like many visual IDEs (Delphi, Visual Ba-
sic,...).
• Class browser with help, so you get instant information about each method.
• Code auto completion, just type the name of an object and after pressing '.' you get all
methods and properties for this object.
• The programming language is C, but you can use some predefined objects.
• The source code is preprocessed to allow a further level of abstraction, adding pseudo-
objects that can be accessed through properties and methods.
Besides, you no longer have to bother with the installation of the individual components (pilrc,
prctools, ...) for the environment as I have also developed an installer.
This program is free for non-commercial use. If you are making money with it you
should share a part of your profits, but I am not going to control you (the generated code has
no backdoors or anything special to be recognized). http://www.digital-kingdoms.net/
palmphi/
4
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EX-
PRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PRO-
CUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSI-
NESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CON-
TRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAM-
AGE.
Contribute? : If you think Palmphi is a good environment and you enjoy using it, help
me develop it further and help other people using it. There are many ways you can contrib-
ute :
• Post programs you compiled with Palmphi (either send me a mail or use the Yahoo
group).
• Write documents describing your experience, problems you encountered and how you
solved them
• Translate a tutorial to another language
• Write a HLP/ CHM file.
• Expand the file parser.c with another useful class
• Improve the help in parser.c
There are MANY ways you can help. I won't pay you (as I get no money for doing this) but you
will be shown as contributor (or maybe co-author?).
Introduction
This booklet covers the basics of creating program’s for your Palm using Palmphi Vis-
ual Designer which I believe is one of the easiest to use, and understand Visual Designers for
the Palm PDA available, and it’s free. I have bought and tried several other Visual Designers
including the add-on for Visual Basic which is an excellent program, but the runtime files
needed for the execution of an application take a significant portion of the limited memory
available in the Palm. With the limited memory that is available in a Palm I hated to waste it
on runtime files. Also being new to Palm programming I spent hours reading, entering the
code as described in the books, and still getting compiler errors some of which seemed to
make no sense to me. With Palmphi I was able to learn the coding and get a program up and
running faster, with fewer error’s, and also less time spent debugging. I feel it is important for
a person new to programming to see results with out spending hours reading, becoming frus-
trated due to constant problems with code errors being reported buy your Visual Designer.
When a program compiles and runs prope rly it helps the new programmer by increasing that
persons confidence, and self satisfaction, which in turn stimulates a greater interest in pro-
gramming. I know that if I enjoy doing something my learning curve and need to increase my
knowledge of that subject is also increased, This I believe is true for all, Palmphi will help you
do this.
♦ I will first discuss the environment installer (11 Mb). files for Palmphi, and setting Cygwin.
bat.
♦ Instalation of Palmphi, Pose, and Pose necessary files.
♦ Configure the settings i n Palmphi.
♦ Next Configuring the Autoexec.bat file Win 98, and ME, then using regedit to setup XP.
♦ Look at the features in Palmphi
♦ Then I will have some sample programs with detailed instructions, pictorials, and code to
help you get started using Palmphi.
5
♦ I will then have some more programs showing how to use the object’s inserted into a Palm
form or forms.
1. Environment installer (11 Mb). This will have these files in it cygwin, prctools, PilRC, and
PalmSDK. This package consists of four files one of which is an executable to extract the
files, and the remaining three are compressed files used by the executable. If you haven't
installed cygwin yet, or you have problems with you current version, then read following
information.
Use the prebuilt installer for cygwin, prctools, PilRC, and PalmSDK. Install it, only if you
don't have any other versions or if you don't mind loosing the ones you have.
• PilRC (GPL) is being developed by :
(c) 1997-1999 Wes Cherry wesc@technosis.com
(c) 2000-2002 Aaron Ardiri aaron@ardiri.com
• prc-tools (GPL) has its home page at http://prc-tools.sourceforge.net/misc/old-new-
pages/prc-tools.html
• palm SDK license can be read after the installation at : ($CYGWIN)\Palmdev\Palm OS
SDK Licenses. Before using the software, you should read this license.
• cygwin (GPL) 's homepage can be reached at http://www.cygwin.com/
2. Palmphi the latest version. At this writing it is Version 1.63
3. Pose the Palm emulator emulator-win.zip.
4. Pose Rom files, these are the files Pose uses to emulate particular Palm operating systems.
5. Pose skins, to have pose look like a particular handheld.
Chapter 1 Setup
Installing the Palmphi Enviromental programs
1. Download or obtain the enviromental installer created and written by Eduardo Terol (You
need to have all the four files, Total : 11 Mb) (remember, that he developed only the installer)
2. Copy all four files to the same directory ( Example C:\temp ) then execute cygwin.exe.
3. When the self-extractor is launched, select a directory to unpack the files to which we will
later make accessible by old DOS programs. Windows XP DOS files are located in C:
\WINDOWS\system32 (e.g. C:\inst) execute the program install.exe there.
4. Select a destination for the file "cygwin.bat",I used C:\PalmDev\Cygwin this is where the
whole installation is unpacked. Other directories that could be used are C:\CYGWIN or D:
\CYGWIN, that is up to you, just keep it all organized. DON'T select C:\Program Files
\Cygwin, because "Program Files" won't be accessible by these unpack utilities. And don't se -
lect C:\cygwin.bat if you don't want to get zillions of files in your root directory. I had the in-
staller ask me where to extract cygwin bat to. In the file window I created a new directory in
C:\PalmDev\ called Cygwin, My Directory looked like this C:\PalmDev\Cygwin It also asked
me for a file name at the bottom there I entered Cygwin.bat and then pressed the OK button
to proceed, then all went well .
5. Wait until the installation is over and answer "yes" to the question if it should perform a
6
test.
6. You can safely delete the installation directory if everything ran ok.
As the main program is changing very often, this installer is intended only for the environ-
ment. The main program must be downloaded separately.
Troubleshooting
If you have any problem check following :
- Do you have more than one copy of cygwin, in your system? Try deleting the old one. Delete
also with the registry editor the path : HKEY_LOCAL_USER\Cygnus Software\cygwin
- Do you have enough free space? with less than 70 Mb don't even try it !
- If you have deactivated 8.3 filename format mirroring, then you have to copy the installation
files to a directory, which is accessible with 8.3 format names. (e.g. c:\inst)
- The test script can be manually executed. It resides on ($CYGWIN) directory. Try executing it
manually and seeing what happens.
Installing Palmphi
7
Configuring your Computer for Palmphi and
Pose.
First we need to determine if Palmphi is working? If so then we are finished and ready
to start programming with Palmphi. If you ran the test in the environmental installer and it
worked correctly we are probably done, and you can skip the rest of this chapter. If not we
need to configure Windows to find the correct directories for the program.
Windows XP
First create a path to your Cygwin directory:
1. Put your mouse pointer on my Computer and Right Click
2. You have now a small window, move your mouse pointer down to properties, and Left
Click. There is now a window called System Prope rties.
3. Left click on the Advanced Tab, Near the bottom of this window is a button labeled Envi-
ronment Variables.
4. Left click on Environment Variables. You should now see a window labeled the same. It
should resemble the picture below.
5. Now in the User variables for whomever
(Your Name?) you should see a variable named
PATH. If so, click on it to highlight it, then click
on Edit, If not Click on the New button and for a
variable name type PATH and for Variable value
in the empty variable values window as below
either empty if new or some stuff in there.
If Empty enter the path to your Cygwin
Directory example (C:\Cygwin or D:\Cygwin or
as in my setup C:\PalmDev\Cygwin) that will
point to your Cygwin.Bat. Next in the same
window enter the information for the Cygwin-
Bin by example ( ;C\Cygwin\Bin or ;D:Cydwin
\Bin or as I have ;C:\PalmDev\Cygwin\Bin )
after doing that your Variable value should look
like C:\Cygwin;C:\Cygwin\Bin. After all is
done click on OK and close all.
If Exist there is already a variable name
called PATH in the variable name window click
the Edit button and add the following after the
other stuff in there example ( C:\Stuff
\morestuff;D;\stuff;C:\Cygwin;C:\Cygwin
\Bin in my case it was C:\PalmDev\Cygwin;C:\Cygwin\Bin ).After you are finished Editing
or Adding click the Ok button to close the window . Then click the Ok button in the Environ-
ment Variables to close this window, and again click the Ok button to close the last window
7. To check this open a dos Window and type Path. Your window should display Path= C:
\whatever else;C\Cygwin;C:\cygwin\Bin. The whatever is the variables that were in
there before you added the new variables and it will vary depending on what programs are
installed. Or as in picture below. Please note that this will vary with each persons setup
due to programs that are installed, but some where in the path you should see C:\Cygwin;
8
8. Next in a Dos window type mount and press enter. This will display the mount points for
Cygwin and also should point to the correct directories as in picture below. If they do then
you should be ready to run the test program Test.Bat in the Cygwin directory and if all is
ok open Palmphi and compile an example program.
9. If it still does not compile right you will have to use regedit. I caution you that if you
make a mistake here you might as well reformat you hard drive, reinstall Windows, then
install the Palmphi files which will probable run with no problem then. I have done it
and after doing so, then reinstalling Windows the setup was a snap, also save all impor-
tant files before proceeding.
Windows 98 & ME
In 98 or ME you don’t have the option of the user variable window so all is done in the auto-
exec.bat and with regedit. Again if Palmphi is working correctly you don’t need these instruc-
tions just start using it all is well.
1. Open a Dos window and type path to check to see what variables are set. It should display
path=C:\Windows;C:\Windows\whatever;C:\Cygwin;C:\Cygwin\Bin if not Right click on
the Autoexec.bat file and chose Edit.
2. In the Edit program enter after The PathC:\Stuff a ;C:\Cygwin;C:\Cygwin\Bin or the ap-
proiate information to point to
Cygwin and Cygwin Bin.
3. Next Save the file as Autoexec.bat
to over write the old, close the Editor,
and reboot then check if Palmphi will
work now.
4. If it still does not compile right
you will have to use regedit. I cau-
tion you that if you make a mistake
here you might as well reformat you
hard drive, reinstall Windows, then
install the Palmphi files which will
probably run with no problem then.
That’s a fact for I have also done it.
Common Problems
The most common problem is cant find lib file, unable to load h file, or file does not exist.
These problems are caused by either an improper install in which case reinstall it again, or
the variables were not set correctly . Then you need to go in and check them as in the last few
steps and if you find an error correct it. If your path and mount points are correct it should
work. I have installed it on several machines and only had problems if another version of
Cygwin existed on the machine in which the previous steps along with some work with rege-
dit corrected the problem.
10
Chapter 2 Using Palmphi
Creating A Shortcut and Starting Palmphi
I am using Windows XP but Windows ME and 98 are very similar.
1. Right Click on your desktop bring up this menu, and point your mouse to Shortcut then
left click as in Figure 1.
2. You should now see a menu as shown in (Figure 2) asking you to chose the location of
your program. This should be ( C:\Palmdev\Palmphi\palmphi.exe) if you did the sug-
gested install Click Next. Otherwise point it to the drive and directory you chose to install
Fig 4 it in.
3. Now you should Fig 5
see a menu titled Se-
lect a Title for the
Program. Change the
title from palmphi.
exe to Palmphi, then
Click Finish.
4. Now there should be an icon in your
window like the one in Figure 4.
Double Click on the Palmphi icon
to stat the program.
5. Now with Palmphi started we must
set a couple of file pointers for
Palmphi to operate properly.
6. Click on Tools, then Settings, this
will display the screen as shown in
Figure 5 displaying the Settings
Menu and displaying the Environment settings. This value should be set to cygwin.bat C:
\Palmdev\cygwin\cygwin.bat and for Emulator C:\Palmdev\Pose\Emulator.exe.
7. After you have selected the proper Environment locations for Palmphi. Left Click on the
OK button, now you are ready to use Palmphi.
8. With Palmphi running it should look similar to Figure 6. You can move and resize the
Create a new
object or c file. Save project file’s Make, compile
your project.
Open an existing Display the ac- Clear all Temp files. This will
object or c file Run the Palm
emulator Pose. tive form delete all Temp files generated
during compile.
Figure 6
11
Edit window to best suit your needs. Now lets di s-
cuss the windows starting with Edit window Fig 7
Palmphi 1.55. As you can see by the pictures,
when you position your mouse pointer over an
icon you get a small blue help window describing
what function that icon will do when clicked.
9. Object Inspector Properties: Figure 7 This is
where the properties can be set for your Applica-
tion Form, and all items inserted into that form.
Figure 7 shows the properties for Multiply Tap-
plication. I wont go into detail on each item be-
cause if you want information on each property
value, click on the description with your mouse
leaving the pointer on the text and a help file will
popup telling you in a brief explanation what
each property is used for .
10. Object Inspector Events: Figure 8, There are no
popup help files for the events window but as you
can see they are self explanatory. Here you can
select event related actions such as pe rforming a
specific action like ONClose, OnOpen, ect. In this
particular form I wanted Focus to be set to a Te-
dit box when the form opened. To do this point
your mouse at the empty frame just left of the
OnOpen label and double click. Palmphi will cre-
ate this event in your Form, then all you have to
do is go there and write the action you want
done.
11. The items that can be inserted into your form are
shown in Figure 9. This is actually attached to
the bottom of the object inspector window. As you
can see these also show a brief description of
each object as you hold the mouse pointer on that
Fig 8
button.
Fig 9
12
First Program
Ok you have Palmphi installed and you are ready to start programming. Here is a sim-
ple program that will be easy to write and confirm that Palmphi was installed and working
properly. This program was copied from the Palmphi tutorial at the Palmphi web site, and was
written by Eduardo Terol.
Char swp[20];
EVENT Button2_OnClick(EventPtr event)
{
Form2.PopUp();
}
A swap area (swp) must be used to communicate between
Fig 20
forms, because with PalmOS it is not assured that your
pointers are not changed between events.
Now switch back to Form2. And press Shift-F12 to got back
to the Form. Select Form2 and go to the Events Tab. Locate
the Event "OnOpen" and double click it.
You will be directed again to the source window. Write the
code below there.
Char tmp[50];
StrPrintF(tmp,"Hello %s\nHow are you?",swp);
Edit2.Text=tmp;
If we want to be able to go back to the previous Form, we have to insert a new button into
form2 and add the following code for the OnClick event see Figure 18.
Form1.Back();
17. Now press the Compile Button or the F9 key to compile your project named My First. If all
compiled correctly with no errors you will have a file in your working directory called my-
first.prc. This file can be run in the emulator or hot-synced to your palm.
18. Click on the run button and the emulator will load and run your program as in Figure 19
and Figure 20.
That completes it for this project. You can play around with the code, or add another
15
Example 1
1. Start Palmphi then go to File|New Project and left Figure 21 click bringing up the Create
project menu see Figure 21. In Project Name enter Example1. Store in dire c-
tory should be C:\Palmdev\Work if
it is not point it to that directory.
We will call this example1 so in
the Application name window enter
example1, and our Application ID
for this project will be EXAM. After
all the information has ben entered
click on the OK button. Figure 22
2. Looking at the Editor window you
will see two files one is noname
and the other if Form1.c. Remove
noname as we did in myfirst pro-
ject. Now bring up the form by pressing Shift + F12, or using the Icon Button in the editor
Figure 22. To display your form in the editor
3. In the Object Inspector under Properties Caption change the caption from Form1 to Mul-
tiply. That’s all the changes that we will make for Form1 Properties.
4. Labels: Enter four Labels into your form Label1, Label2, Label3, and Label4. Now we want
to change the text entered into the Labels by Going to
the Object Inspector - Properties Window, and Figure 23
changing the information in the Caption Window for
each Label. Start with Label1 and change it’s Caption
text to Enter A Number. Label2 will be changed to
Enter A Multiplier, while Label3’s Caption will be-
come Precision Value Between 0 and 9. And La-
bel4’s Caption will be changed to Answer. That’s all
for the Object Inspector and Label’s. Now position
the Labels similar to what is in Figure 23.
5. Edit Boxes: New create four Edit Boxes, Edit1, Edit2,
Edit3, and Edit4, then position them with your
mouse as in Figure 24. Now we want to set the Prop-
erties for these four Edit Boxes in the Object Inspe c-
tor. Set these values to the values in the chart below.
6. Buttons: Create three Buttons on the Form. Button1,
Button2, Button3 from left to right near the bottom of
the Form1, See Figure 25 for layout of the buttons. Figure 24
Starting with Button1 in the Object Inspector Prop-
erties Window change it’s Caption to Do It, Next the
middle Botton2, change it’s Caption to Clear, and
Button’s3 Caption should be Exit. As you see in Fig-
ure 26. There that’s it for all the Form Object’s.
1616
7. Code:With Form1 displayed double click on the Do It button, double clicking on this but-
ton will display the Event procedure for that button as in Figure 27 below. button.
Now enter the code below that is Blue in Italics, as the code in color is generated when you
double click on that particular
EVENT Button1_OnClick(EventPtr event) // Event code for Do It button
{
// Return "false" to execute default Figure 25 Figure 26
message handling
float n,m,a; // n = Number, m = Multi-
plier, a = Answer
int p=1; // p = Precision
n=Edit1.AsFloat(); // Get input and
change to float
m=Edit2.AsFloat();
p=Edit3.AsFloat();
a=m*n;
Edit4.AsFloat(p)=a; //Display Answer
return true;
}
Now Double Click on Button2 the button labeled Clear. You now should the Event Procedure
for button2 the Clear button, then again enter the code below in Blue Italic.
EVENT Button2_OnClick(EventPtr event)
{
// Return "false" to execute default message handling
Edit1.Delete(0,6); // Clear Edit1 from character position 0 to 6 which is MaxChars
Edit2.Delete(0,6);
Edit3.Delete(0,1); // Clear Precision or Edi t3 from charactor position 0 to 1
Edit4.Delete(0,14);
Edit1.SetFocus(); // Set Focus to Number box on clear
return true;
}
Next double click on Button3 the Exit button, and enter the code shown below in Blue
Italic.
EVENT Button3_OnClick(EventPtr event)
{
// Return "false" to execute default message handling
FrmCloseAllForms();
TApplication.Terminate(); //End
return true;
}
Finaly we need to go to the Object Inspector Events, Then in the dropdown window, select
Form1 Tform, 28. Find the On Open, put your mouse pointer on it and double click. This will
display the event procedure shown below. Again enter the code shown in black italics.
EVENT Form1_OnOpen(EventPtr event)
{
// Return "false" to execute default message handling
Edit1.SetFocus(); //Set focus to Edit1 on startup
return true;
}
That’s all the code that is entered into this program. You can compile the code now, and if
there are any errors a message box will popup as in Figure 29 showing where the error is.
Double click on the error in the box and you will be taken to the line in the Editor containing
17
the error. If you accidentally add an extra ( or ) the error will be larger as in Figure 30. In Fig-
ure 29 you see two warnings, One is an n function F2A, and the other is a unused variable
named w. The program still compiles and will work fine, I could chose to disable these warn-
ings by editing the make file in the Palmphi directory, but I would rather be aware of any
warnings that accrue during the compi le and chose to disregard them or correct them at my
own discretion.
Figure 29
Figure 28 Figure 30
After a successful compile Palmphi will create a file called Example1.rcp this is the program
for your palm which can be ran in the emulator or installed in your palm. When ran in the
emulator it will look like images below.
Example 2
This is an enhancement of Example 1 which will automatically adjust the size of the second
value in Text.Delete to handle different sized Answer Displays, also convert Float to a String,
and manipulate it a little.
1. Increase the MaxChars for Edit4 from 14 to 24.
2. Add a new Edit label. Call this Edit 5. Set it to Read only, and Underlined. Then enter the
following code in Blue Italic
18
EVENT Button1_OnClick(EventPtr event)
{
// Return "false" to execute default message handling
float n,m,a; // n = Number, m = Multiplier, a = Answer
int p=0;
Char tmp[20];
Char ans[50];
n=Edit1.AsFloat(); // Get input and change to float
m=Edit2.AsFloat();
p=Edit3.AsFloat();
a=m*n;
Edit4.AsFloat(p)=a; //Display Answer
StrCopy(tmp,Edit4.Text());
StrPrintF(ans,"Here is Your Answer %s",tmp);
Edit5.Text=ans;
return true;
}
EVENT Button2_OnClick(EventPtr event)
{
// Return "false" to execute default message handling
Edit1.Delete(0,1+Edit1.Length());
Edit2.Delete(0,1+Edit2.Length());
Edit3.Delete(0,1); // Clear Precision or Edit3 from charactor position 0 to 1
Edit4.Delete(0,1+Edit4.Length());
Edit5.Delete(0,1+Edit5.Length());
Edit1.SetFocus(); // Set Focus to Number box on clear
return true;
}
EVENT Button3_OnClick(EventPtr event)
{
// Return "false" to execute default message handling
FrmCloseAllForms(); // Close Form
example1.Terminate(); // End Program
return true;
}
EVENT Form1_OnOpen(EventPtr event)
{
// Return "false" to execute default message handling
Edit1.SetFocus(); //Setfocus to Enter Number Edit
box when form opens.
return true;
}
There that’s all the code. Now Compile it and run it in
the Emulator. The result should be as in Figure 34.
19
Example 3: Working with Char, String
Manipulation, Adding an Icon.
In this example we will create four text boxes, three of which we can enter a name,
Last Name, Middle Name, then First Name. Also we will create an Alert Box to notify us that
we did not enter data in aa input box. After entering the name you can click on the Do It But-
ton and have the fourth Text Box display the full name by combining the strings. Also we will
insert a Start Icon that will be displayed as the Icon for this program on your Palm, include
a Version Number, and select a Category for the Palm to display this program in.
1. Start by creating a new Project. In the Project Name Window enter Example3, In the Store
in Directory Window have it point to the directory you want your files stored in., Such as
C:\Palmdev\Work. Then for the Application Name Window type in Example3.Finaly enter
PLE2 into the Application ID Window then Click on the OK button to take you back to the
Editor Window.
2. Open the Object Inspector Window Properties as in Figure 35 to display Example3
Figure 35 Tapplication. Now enter 1.00 for a Version Number in the appropriate
Window. As you work with an application and modify it you will
probably want to increase the Version number to reflect improve-
ments in your program. Next we want to enter a category for this
application which will determine in which window on the Palm
our program Icon will be displayed in. For this application I have
chosen All for the Category window. We could have used
Games, Work, Personal what ever suits your needs.
3. Creating an Icon: I use Windows Paint for
this although there Figure 36
are other programs
avai lable witch
could do the job.
Start Paint and set
the Attributes as
in Figure 36 to 36
X 36 This could
also be 32 X 22 or
22 X 22 Pixels,
Note ( When using
32 X 32 keep the
lower area of your
Icon clear as the
name of your application will be placed there) and Color to Black
and White. Next in the View box set Custom to 600% which will
give you a decent sized work area. Create your Icon as in Figure
Figure 37 37. You can create any image you want, that is up to you but
for this Example I kept it simple. Click on the File then select
Save As, and give your Icon a name such as Example3 but
make sure you save it as a two color BMP file. Chose the di-
rectory you want to save it to such as C:\Mydocuments, or to
the directory you created your application in C:\Palmdev
\Work\Example3.
4. In your Properties Window select Icon then click on the
Yellow Icon and this will display a directory tree. Point this
to your Icon file as in (C:\Palmdev\Work\Example3
\Example3.BMP). There now when you load your program into
the Emulator or your Palm this Icon along with your program
name will be displayed on the main screen.
20
5. Form1 should be displayed on your Editor Window, in Figure 38
the Properties Window for Form1 change the caption
to Example3. Next add three Labels to this form, and
four Edit Boxes, as in Figure 38. In Label1 Caption
type Enter Your Last Name, for La bel2.Caption should
read Enter Your Middle Name., and finaly Label3.
Caption add Enter Your First Name. Now
Figure 39 you should position them as in Figure 38 so
that the text is
Properties Edit 1 Edit 2 Edit3 Edit4 centered in the
Width 80 80 80 140 window. The
four Edit Boxes
Read Only False False False True
should have
Underlined True True True True their properties
Multilined False False False True set as in the ta-
ble in Figure 39
MaxChars 20 20 20 0 and positioned as in Figure 38 with Edit4 Showing
AutoShift True True True False three lines.
6. Next we need to add two Buttons, as in Figure
Numeric False False False False 38. To our Form1. The first Button will be labeled
Do It, and the second Button will be labeled Clear.
7. Alert Box: Click on the TAlert Window to create
an Alert Box then set the properties as in Figure
40. The Message Window should contain the fol-
Figure 40
lowing text- ^1 - this will allow it to handle the
three separate messages . We will leave the
Talert name as Alert1 so when we want to call it
we just call Alert1 from our error detection pro-
cedure.
8. The Code: Double click on the Do It Button and
enter the code below shown in Blue Bold, The
Code in Green is generated by Palmphi, and the
code in Gray are commnents which do not affect
the operation of the program lettering. ^1 in Message Window as above.
Now Double Click on the Clear Button and enter the text
in BlueBold Note the Comments are in Gray.
22
Example3 Form1.c
Char Lname[40];
Char Mname[40];
Char Fname[40];
Char FullName[120];
UInt16 F,M,L,Full,alert=0;
int control=0; //0 = False 1 = True
EVENT Form1_OnOpen(EventPtr event)
{
// Return "false" to execute default message handling
Edit1.SetFocus();
return true;
}
23
Example 4 Creating a Data Base Similar to
Memo
In this Example I will demonstrate creating a simple Data Base named StuffDB
with three data entry fields. Two of the fields will hold 30 characters of text which can be
expanded needed by just declaring larger values for the character array strings. When I
defined the structure I named the character arrays Fname, and Lname. The names could
be changed to any name you think is appropriate for your application, The array length for
Fname should not be changed as this also must be displayed in the list box of form 1 along
with a number, and if made too long would flow past the right edge of the list box. LName
array length could be increased to 1,000 if you needed as long as you changed the text box
properties to multiline and string length to an appropriate value. The edit box for the float
value is set to eight characters, and formatted to display two decimal points when viewed.
You will also notice that I have used procedures and called them from within the events
procedures of the form, this saves a lot of repetitive typing, and also makes it easier to read
the code. I have also used some if, for, and else statements for control of the program and
to prevent it from generating an error when an empty input box is saved. The character ar-
ray All is used to store all the Lname (or description’s) read from the data base and stored
there. If you want to increase this so that you can display a
larger list increase this by multiples of Fname array length
example (All[300] will hold 10 Fname[30] or 10 X 30 =
300) will allow 10 titles to be di splayed in the list box.
1. To make this example create a new project give it a name,
and an ID, such as MyData, and LTOJ for the ID as I
used in this example.
2. The Form1 properties should be , Save Behind is set at
False, and Modal is also False.
3. Next add a list box to Form1 with the properties values
set as in picture to the right.
4. Then create a Button and place it in Form1 bellow the list
box, and name it Add Record.
5. Now create a new form Form2 and set its properties val-
ues to Modal True, and Save Behind to True.
6. In Form2 cre-
ate three labels
Description,
Details, and
Float .
7. Create three
Edit Boxes in
Form2 with the
values set as in
picture below
from left to
right starting
with Edit 1 on
the left.
8. Near the bo t-
tom center of
the Form2 also
add a Button
24
and name it Done.
That’s all the object we will be using in this example, You can change the Label names or
rename the Button’s to whatever suits your needs. Next comes the code for the program. I
first declared then wrote the procedures I would use in this program. As the program de-
veloped I had to make some modifications to my code and the logic I used in the program.
The advantage of programming this way is that all the code is in one area, you do not need
to search through the entire program searching for the code used to open, close, or write
your file. Instead just look for the procedures to find the code.
The code for this program is based on some of the code in Mr.Eduardo Terol.
Getting started book for Palmphi, at his web site.
The Code I have written is colored Blue, Green is the code generated from Palmphi, and all
comments are in Gray and unnecessary for the program to operate, but make understand-
ing what you have done easier if later you want to reuse the code or to reference it.
Below is the code for Form1.C
25
ATestDB.Read(si,&Stuff,sizeof(Stuff));
Edit1.Text=Stuff.FName; // Refresh the data on Form2.c
Edit2.Text=Stuff.LName;
Edit3.AsFloat(2)=Stuff.MNumber;
}
}
static Do_Read() // Read DB, resize, add numbers, and insert a comma
{
Char Tstr[30]; // Temp string
Int16 i=0,j,l=26; //i= record count,j= string length, l= length of string
if(ATestDB.RecordCount()>0)
{
StrCopy(All," "); //clear string to prevent errors in displaying
// data in form1 list box
for (i=0;i<ATestDB.RecordCount();i++) //loop untill i = record count
{
ATestDB.Read(i,&Stuff,l); // Read 26characters from db file
StrCopy(NFN,Stuff.FName); // put FName data into NFN string
if(l<StrLen(NFN)) NFN[26]=0;
for(j=0;j<StrLen(NFN);j++) // loop to read each character in string
{
if(NFN[j]==',') NFN[j]=' '; //remove user entered commas and insert space
}
if(StrLen(NFN)>0) StrCat(NFN,","); //if string empty skip, else Add comma
StrPrintF(Tstr,"%d.%s",i+1,NFN); //add a file number
StrCat(All,Tstr); //add this to our All list
}
}
}
26
ListBox1.Erase();
ListBox1.Items=All;
ListBox1.Draw();
Do_Open();
Do_Read();
Do_Close();
ListBox1.Erase();
ListBox1.Items=All;
ListBox1.Draw();
return true;
}
27
if(Control==true) {Do_Insert();}
if(Control==false) {Do_Modify();}
Do_Close();
}
Form1.Show();
Form2.Back();
return true;
}
After you have completed entering the code Compile the program, and if all com-
piled well execute it in the emulator. Pictures of program running are below. This program
works well and I could not get it to generate an error message, but I did not over flow the
All array which I believe will start giving erroneous readings if you exceed the character
length of the array so some logic should be added to prevent it from happening .
28
Example 5 Using the values returned from
Alert Message For Controling a Program
This example shows how to get the value returned from an Alert form button pressed and
use it to control how other objects in a form behave. Steps write this example are as fol-
lows.
1. Create a new project and name it Example5, in directory Example5, and an ID of PLE5.
2. Create two Talerts called Alert1, and Alert2. Then enter the AlertType, Name, Title, But-
tons, and Message as in pictures below.
3. Next create two Buttons, Button1 is named Alert 1, and Button2 is named Button2 !.
Change Button2 Visible Property to False. We want this button hidden when applica-
tions starts.
4. Now create to Edit boxes, Edit1 has a length of 140, Underlined = False, and Max Char-
acters = 0. Edit2 will have a Width of 140, it will be Underlined = True, and Max Char-
acters = 15. Also for Edit2 Events On_Enter douple click to have Palmphi generate an
event for it so that when Edit2 is clicked Button2 will show.
Now you can enter the code, Rember the Code in Green is generated by Palmphi, The text
in Gray is only for information for the writer or other people to help them understand the
code. Blue will be the code you will be entering into the form.
// Below shows how to use the information returned from TAlert2 to control program
EVENT Button2_OnClick(EventPtr event)
{
if(Edit2.Length()<=1) //**If no data entered show Alert2
29
{
if(Alert2.Show()==false)
{
Edit1.Text="Ok Enter some Text";
Edit2.SetFocus();
} else {
Button2.Visible=false;
Edit1.Text="You Chose to Cancel";
}
}
Edit2.Delete(0,15);
return true;
}
30
31