beginners palm programming

Upload: marcioemail

Post on 30-May-2018

226 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/14/2019 Beginners Palm Programming

    1/31

    WITH

    By LeRoy Olson

  • 8/14/2019 Beginners Palm Programming

    2/31

    Written By

    LeRoy T Olson

    [email protected]

    February 11 2004

  • 8/14/2019 Beginners Palm Programming

    3/31

    Index

    About this booklet Page 4

    About PalmphiPage 4The Future of this Booklet Page 4Introduction Page 5Files Needed to use Palmphi, and Pose the emulator Page 6

    Chapter 1 SetupWindows Installation of the Environment installer (11 Mb).Page 6

    Installing Palmphi. Page 7Installing Pose and support files. Page 7Configuring your Computer for Palmphi and Pose. Page 8

    Windows XP configurationPage 8Windows 98 & ME configuration Page 9Common Problems Page 9Using RegEdit Page 9

    Chapter 2 Using PalmphiCreating a Shortcut on the Desktop for Palmphi and Starting PalmphiPage 11First Program Page 13Example 1 Using the Edit Box with Float and strings Page 16Example 2 Float to String, String Manipulation Page 18

    Example 3 Working with Char, String Manipulation, Adding an Icon. Page 20Example 4 Creating a Data Base Similar to Memo Page 24Example 5 Using the values returned from Alert Message For

    Controlling a Program Page 29

  • 8/14/2019 Beginners Palm Programming

    4/31

    About This Booklet

    This booklet was written for the person new to Palm application programming with atleast a limited knowledge of the C programming language to help understand some of the codeconventions 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 theform, 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 meknow so I can make the necessary changes.

    All the code in this booklet was written with Palmphi Versions 1.52 through Version1.62 . The executable programs or PRC s have been tested and work properly using Pose thePalm Emulator set up to emulate the Palm Pilot Pro with 2 Meg of memory, and version 3.3 ofthe Palm OS Software.

    My operating system is Windows XP Professional on a 1 Ghz Pentium, I also have itsetup 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, andAutoexec.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 applications and documentation for using Palmphi to createPalm 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 accessmore than one Data Base at a time, and update data simultaneously in more than one DataBase.

    Also I have chosen to use Euphoria ( A basic type language for Windows or Linux ) towrite applications for viewing and editing data on your Desktop Computer for use in yourPalm. The Euphoria site is://www.rapideuphoria.com/.

    About PalmphiThese are exce rpts 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 youshould share a part of your profits, but I am not going to control you (the generated code hasno backdoors or anything special to be recognized). http://www.digital-kingdoms.net/palmphi/

    4

  • 8/14/2019 Beginners Palm Programming

    5/31

    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 WARRANTIESOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENTSHALL 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 ANYWAY 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, helpme develop it further and help other people using it. There are many ways you can contri b-ute :

    Post programs you compiled with Palmphi (either send me a mail or use the Yahoogroup).

    Write documents describing your experience, problems you encountered and how yousolved 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 youwill be shown as contributor (or maybe co-author?).

    Introduction

    This booklet covers the basics of creating programs for your Palm using Palmphi Vis -ual Designerwhich I believe is one of the easiest to use, and understand Visual Designers forthe Palm PDA available, and its free. I have bought and tried several other Visual Designersincluding 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 memoryavailable in the Palm. With the limited memory that is available in a Palm I hated to waste iton runtime files. Also being new to Palm programming I spent hours reading, entering thecode as described in the books, and still getting compiler errors some of which seemed tomake no sense to me. With Palmphi I was able to learn the coding and get a program up andrunning faster, with fewer errors, and also less time spent debugging. I feel it is important fora 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 properly it helps the new programmer by increasing thatpersons 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 myknowledge of that subject is also increased, This I believe is true for all, Palmphi will help youdo 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 in 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

  • 8/14/2019 Beginners Palm Programming

    6/31

    I will then have some more programs showing how to use the objects inserted into a Palmform or forms.

    Files needed to use Palmphi and

    Pose the emulator For Windows.

    1. Environment installer (11 Mb). This will have these files in it cygwin, prctools, PilRC, andPalmSDK. This package consists of four files one of which is an executable to extract thefiles, and the remaining three are compressed files used by the executable. If you haven'tinstalled cygwin yet, or you have problems with you current version, then read followinginformation.Use the prebuilt installer for cygwin, prctools, PilRC, and PalmSDK. Install it, only if youdon'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 [email protected](c) 2000-2002 Aaron Ardiri [email protected]

    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 OSSDK 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.633. 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 SetupInstalling the Palmphi Enviromental programs

    1. Download or obtain the enviromental installer created and written by Eduardo Terol (Youneed 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 willlater 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 inC:\PalmDev\ called Cygwin, My Directory looked like this C:\PalmDev\Cygwin It also askedme for a file name at the bottom there I entered Cygwin.bat and then pressed the OK buttonto proceed, then all went well .

    5. Wait until the installation is over and answer "yes" to the question if it should perform a6

  • 8/14/2019 Beginners Palm Programming

    7/31

    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.

    TroubleshootingIf you have any problem check following :- Do you have more than one copy of cygwin, in your system? Try deleting the old one. Deletealso 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 installationfiles 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 itmanually and seeing what happens.

    Installing Palmphi

    Create a directory for Palmphi Example, C:\CYGWIN\PALMPHI D:\CYGWIN\Palmphi or asI did C:\PalmDev\Palmphi. Next use WinZip or any other unzipping program to unzip palm-phi.zip to this directory. Thats all there is to installing Palmphi but you may need to edityour registry in Win XP, or your configure file in Win 98, or ME and we will discuss thatshortly. After Installation start Palmphi and set the environment in Tools Settings Environ-ment for Cygwin and Pose. Also look in Chapter 2 Page 11 for details on setting up.

    Installing Pose and support files.You will first need to create a directory for it, as in ( C:\PalmDev\Pose ) then unzip the filethere. Make sure you have the properties set in your Unzip program to preserve directory

    structures. When you unzip emulator-win.zip to the Pose directory it will also create a Docs,and Scripting\Pearl directory and insert more files there. After unzipping Pose to the appro-priate directory create two more directories in Pose Skins, and Rom ( C:\PalmDev\Pose\Skins, and C:\PalmDev\Pose\Rom . Unzip emulator-skins-19. to the Skins Directory.Next Unzip the Rom files to the Rom directory. If you only need one file for your Palm just un-zip the appropriate file to the Rom directory. If you want to develop programs for other Palmdevices then unzip all that you wi ll need.On the left is a partial list of the rom files, some are single files while others are multiple files.I also created a short cut to the Emulator on my desktop to test and examine programs

    downloaded from the internet.This is much faster and easierthan Hot-Syncing to my Palm forinitial testing. I would also sug-

    gest reading the docs on using,and setting the Rom, and Skin,in the Emulator.

    7

  • 8/14/2019 Beginners Palm Programming

    8/31

    Configuring your Computer for Palmphi andPose.

    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 itworked correctly we are probably done, and you can skip the rest of this chapter. If not weneed to configure Windows to find the correct directories for the program.

    Windows XPFirst create a path to your Cygwin directory:1. Put your mouse pointer on my Computer and Right Click2. You have now a small window, move your mouse pointer down to properties, and Left

    Click. There is now a window called System Properties.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 namedPATH. If so, click on it to highlight it, then clickon Edit, If not Click on the New button and for avariable name type PATH and for Variable valuein the empty variable values window as beloweither empty if new or some stuff in there.

    If Empty enter the path to your CygwinDirectory example (C:\Cygwin or D:\Cygwin oras in my setup C:\PalmDev\Cygwin) that willpoint to your Cygwin.Bat. Next in the samewindow 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 looklike C:\Cygwin;C:\Cygwin\Bin. After all isdone click on OK and close all.

    If Exist there is already a variable namecalled PATH in the variable name window clickthe Edit button and add the following after theother 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 Editingor 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 e lse;C\Cygwin;C:\cygwin\Bin. The whatever is the variables that were inthere before you added the new variables and it will vary depending on what programs areinstalled. Or as in picture below. Please note that this will vary with each persons setupdue to programs that are installed, but some where in the path you should see C:\Cygwin;

    8

  • 8/14/2019 Beginners Palm Programming

    9/31

    8. Next in a Dos window type mount and press enter. This will display the mount points forCygwin and also should point to the correct directories as in picture below. If they do thenyou should be ready to run the test program Test.Bat in the Cygwin directory and if all isok 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 youmake 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 t hen. I have done i tand after doing so, then re installing Windows the set up was a snap, also save all impor-

    tant files before proceeding.

    Windows 98 & MEIn 98 or ME you dont 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 dont 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 onthe 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.batto over write the old, close the Editor,and reboot then check if Palmphi willwork now.4. If it still does not compile rightyou will have to use regedit . I cau-tion you that if you make a mistakehere you might as well reformat youhard drive, reinstall Windows, theninstall the Palmphi files which willprobably run with no problem then.Thats a fact for I have also done it.

    Common ProblemsThe 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, orthe variables were not set correctly . Then you need to go in and check them as in the last fewsteps and if you find an error correct it. If your path and mount points are correct it shouldwork. I have installed it on several machines and only had problems if another version ofCygwin existed on the machine in which the previous steps along with some work with rege-dit corrected the problem.

    Using RegEdit XP 98.

    Backup your important fi les and also create a restore point before pro-ceding.

    1. Go to the start menu and select run, and click on it. In theRun window type regedit then click Ok This will open the pro-gram regedit.exe and you will be in a window like the one on theLeft.2. Click on the HKEY_CURRENT_USER to expand this directory.After expanding this dire ctory scroll down until you see a direc-tory called Software.3. Expand the software directory by clicking on it. Now you need

    9

  • 8/14/2019 Beginners Palm Programming

    10/31

    to find the directory namedCygnus Solutions .4. After expanding CygnusSolutions you will see twodirectories, the first shouldbe Cygwin, the second is

    CYGWIN.DLL setup. Expandthat directory.5. The directory should ex-

    pand and the directory structure should look like the pi c-ture on the right. We will have toadd or edit the mounts 00 to 03.If they do not exist you can cre-ate them by right clicking onmount, then left click onKey as in picture to the left.Name these mounts 00 to03 as in picture on right.

    6. Next click on 00 and youwill see a window box likethe one below with only oneIcon and REG_SZ (valuenot set). We need to changethis.

    7. In this window right click to

    display a selection window labeled New.Click on that then select string value andclick. Next name this native then create an-other and name it unix.

    8. Highlight the first icon you created andclick on Modify. Now you will see a windowlike the one on the right called Edit String.In this window box enter C:\ and click OKnow highlite the second icon called unix

    and enter / . Click Ok,9. Now highlight the 01 directory and also create two string values the first is native, and the

    second is unix.In the Edit string window box enter for native value C:\Cygwin or whateverpoints to your Cygwin directory. For the unix value open the Edit String window and en-ter /cygwin or again whatever points to Cygwin directory.

    10. Do the same with 02 and in the native icon enter C:\Cygwin\Bin or whatever points tothat directory. Unix would be /bin or the directory for Cygwin Bin.

    11. Add this to the 03 directory so that it points to prc tools. Native = C:\Cygwin\ PRC-Tools

    or again point to which ever directory prc tools is in. unix would be /prc-tools.Thatshould do it and now Palmphi should work.

    The directories will vary depending on which drive and which directory you chose to un packthe files to. The paths I have shown above would only be good if you installed them just as inthe examples shown previously.

    10

  • 8/14/2019 Beginners Palm Programming

    11/31

    Chapter 2 Using PalmphiCreating A Shortcut and Starting Palmphi

    I am using Windows XP but Windows ME and 98 are very similar.1. R igh t C li ck 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 Cl ick Nex t . Otherwise point it to the drive and directory you chose to install

    it in.3. Now you shouldsee a menu titled Se-lect a Title for theProgram. Change thetitle from palmphi.exe to Palmphi, thenCl i c k F in i s h .

    4. Now there should be an icon in your

    window like the one in Figure 4. Double Clickon the Palmphi iconto stat the program.

    5. Now with Palmphi started we mustset a couple of file pointers forPalmphi to operate properly.

    6. Cl ick on Tools, then Settings, thiswill display the screen as shown inFigure 5 displaying the SettingsMenu and displaying the Environment settings. This value should be set to cygwin.bat C:\ Pa l m d e v \ c y gw i n \ c y gw i n . b a t and for EmulatorC:\ Pa l m d e v \ Po s e \ E m u l a t o r . e x e .

    7. After you have selected the proper Environment locations for Palmphi. Le f t Cl ick on theOK 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

    Fig 4Fig 5

    11

    Make, compile

    your project.

    Open an existing

    object or c file

    Save project filesCreate a new

    object or c file.

    Figure 6

    Run the Palmemulator Pose.

    Display the ac-

    tive form

    Clear all Temp files. This will

    delete all Temp files generated

    during compile.

  • 8/14/2019 Beginners Palm Programming

    12/31

    Edit window to best suit your needs. Now lets di s-cuss the windows starting with Edit windowPalmphi 1.55. As you can see by the pictures,when you position your mouse pointer over anicon you get a small blue help window describingwhat function that icon will do when clicked.

    9. Object Inspector Properties: Figure 7This iswhere the properties can be set for your Applica-tion Form, and all items inserted into that form.Figure 7 shows the properties for Mu l t i p l y T a p -p l i ca t ion . I wont go into detail on each item be-cause if you want information on each propertyvalue, click on the description with your mouseleaving the pointer on the text and a help file willpopup telling you in a brief explanation whateach property is used for .

    10. Object Inspector Events: Figure 8 , There are nopopup help files for the events window but as youcan see they are self explanatory. Here you canselect event related actions such as pe rforming aspecific action like ONClose, OnOpen, ect. In thisparticular form I wanted Focus to be set to a Te -dit box when the form opened. To do this pointyour mouse at the empty frame just left of theOnOpen label and double click. Palmphi will cre-ate this event in your Form, then all you have todo is go there and write the action you wantdone.

    11. The items that can be inserted into your form areshown in Figure 9 . This is actually attached tothe bottom of the object inspector window. As you

    can see these also show a brief description ofeach object as you hold the mouse pointer on thatbutton.

    12

    Fig 7

    Fig 8

    Fig 9

  • 8/14/2019 Beginners Palm Programming

    13/31

    First ProgramOk 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 workingproperly.This program was copied from the Palmphi tutorial at the P a l m p h i web site, and waswritten by E d u a r d o T e r o l .

    Create the Project

    1. First click on the My Computer Icon to access drive c: or whatever drive you installedPalmphi into then create a directory for your project. Iprefer Work as my directory name but whatever youchoose it will give you a place to store all your files. Ex-ample C:\Palmdev\Work .

    2. Next select File| New Project .3. Create Projectwindow will display empty fields except

    for the Storein Directory,and thisprobably is

    displaying C:\Palmdev\palmphi .First weshould changethis as wedont reallywant a lot ofunnecessaryfiles layingaround in thePalmphi direc-tory. On theright side ofStore in Directory is an image of a small folder, click on that Icon and yourdirectory tree will be displayed. Find and click on the directory you have created to storeyour files in, C:\Palmdev\Work or C:\MyDocuments\Work, whatever location you wouldlike to use.

    4. With that completed we click on the empty field next to Project Name and type in m y - f i rs t . This will be our project name and it will also create a subdirectory called m y f i r s t an exampleis C:\Palmdev\Work\myfirst.

    5. Now click on the empty field by Application Name and again type in myfirst here. Thiswill be the name of our TApplication.

    6. Finally we will need to give our application an ID. We will discuss Application IDs later.Enter FIRS as the Application Name for now. Thats it for the Create a Project window,now double check to make sure all is

    correct then click on the OK button.This will take you back to the Editorwindow .

    7. Now you will see two files. One will benamed Form1.cwe want to keep thisone. We will not need the file on theright named noname so left click on it.Then when you see the window as inpicture to the right, chose Close fileand click it. You will then ask you to

    13

  • 8/14/2019 Beginners Palm Programming

    14/31

    confirm deleting this filewith a message box con-taining the name of the file.Make sure you have chosento delete the correct file byverifying the file name to

    the one displayed in thewindow, then click on Yes.8. Finally after deleting theunnecessary file your editorwindow should have a filenamed Form1.c and a formnamed Form1 like in the

    picture to the left.9. Changing property values: Form1 or also called the Main

    Form and it will need its Caption changed to My Firs t . Change the Caption in the ObjectInspectors ComboBox labeled Caption by clicking on the window to the left of the Captionwhere you see Form1. Change the value for the property Caption toMy Firs t and thenPress Enter.

    10. Insert new components: Now insert a Label (Press the button with the word LABEL un-der the components in the object inspector See Figure 9 , and then click anywhere onForm My First). Change the caption of the label toE n t e r y o u r n a m e :.NOTE: You can switch at any time between Object inspector and Editor with F11. With Shift-

    F12 you switch between Form and Source file

    11. Insert a new TEdit component. You can see which com-ponent corresponds to each button by leaving the mousecursor over the button for a while. The name of the corre-sponding component appears. Now make it underlinedby going to the object inspector, then clicking on theproperty value of underlined, and se lecting True. Click onit to change underlined to True. To allow data to be en-

    tered into this Edit box we need to change the propertyvalue for MaxChars to 10. This will make the TEdit1 bigenough to hold a name of 10 characters.

    12. To resize Edit1 in the window on Form1 My Firs t justclick on one of the small rectangles and drag out to thesize you need.

    13. Now insert a Button. Place it under the Edit1. Change itscaption to "OK". If you followed the right order, your but-ton name is "Button1".

    14. Now we need a newForm As in Figure 16.Our greeting form -.Click on the first Com-

    ponent Button (theTForm button). Changethe properties of theForm to make itsmaller. Or drag itsmaller if you prefer.Width and Heightshould be around 120.Top and Left around20. Change the caption

    14

    Fig 14Fig 15

    Fig 16

    Fig 17

  • 8/14/2019 Beginners Palm Programming

    15/31

    to an empty string(the title disappears).Change both Modaland Save Behind to"true"

    15. Now drop a TEdit onto

    Form2. Make it multi-line and big enough tocontain more than oneline.

    16. Writing the code Now is time to go backto Form1. Press ShiftF12 and on the Tab goto Form1.c, now pressShift - F12 again.We've got our inter-face. Now we have towrite some code.Double cli ck on the"OK" button. You are now in the code window. Write the fol-lowing code there that is in Blue Bold Text.Declare swp as a Char array. It should look like Figure 17.Char swp[20];S t r Co p y (s w p , E d i t 1 . T e x t );

    Form 2 .PopUp();

    Cha r sw p[20 ];

    EVENT Button2_OnClick(EventPtr event){Form 2 .PopUp();

    }A swap area (swp) must be used to communicate betweenforms, because with PalmOS it is not assured that yourpointers are not changed between events.Now switch back to Form2. And press Shift-F12 to got backto the Form. Select Form2 and go to the Events Tab. Locatethe Event "OnOpen" and double click it.You will be directed again to the source window. Write thecode below there.

    Ch ar tm p[50 ];

    S t rPr in tF(tm p , "He l lo %s \ n How are you ?", sw p);

    E d i t 2 . T e x t =t m p ;

    If we want to be able to go back to the previous Form, we have to insert a new button i ntoform2 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 allcompiled 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 19and Figure 20.

    That completes it for this project. You can play around with the code, or add another15

    Fig 18

    Fig 19

    Fig 20

  • 8/14/2019 Beginners Palm Programming

    16/31

    16

    Example 11. Start Palmphi then go to File|New Project and left click bringing up the Create

    project menu see Figure 21. In Project Name enter Example1. Store in direc-tory should be C:\Palmdev\Work ifit is not point it to that directory.

    We will call this example1 so inthe Application name window enterexample1, and our Application IDfor this project will be EXAM. Afterall the information has ben enteredclick on the OK button.

    2. Looking at the Editor window youwill see two files one is nonameand the other if Form1.c. Removenoname as we did in myfirst pro-ject. Now bring up the form by pressing Shift + F12, or using the Icon Button in the editorFigure 22. To display your form in the editor

    3. In the Object Inspector under Properties Caption change the caption from Form1to Mul-

    tiply. Thats 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 tothe Object Inspector - Propert ies Window, andchanging the information in the Caption Window foreach Label. Start with Label1 and change its Captiontext to Enter A Number. Label2 will be changed toEnter A Multiplier,while Label3s Caption will be-come Precision Value Between 0 and 9. And La-bel4s Caption will be changed to Answer. Thats allfor the Object Inspector and Labels. Now positionthe 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 yourmouse as in Figure 24. Now we want to set the Prop-erties for these four Edit Boxes in the Object Inspec-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 ofthe Form1, See Figure 25 for layout of the buttons.Starting with Button1 in the Object Inspector Prop-erties Window change its Caption to Do It, Next themiddle Botton2, change its Caption to Clear, andButtons3 Caption should be Exit. As you see in Fig-ure 26. There thats it for all the Form Objects.

    16

    Figure 21

    Figure 22

    Properties Edit1 Edit2 Edit3 Edit4

    Width 40 40 10 80

    ReadOnly False False False True

    Underlined True True True True

    MaxChars 6 6 1 14

    Numeric True True True True

    Figure 23

    Figure 24

  • 8/14/2019 Beginners Palm Programming

    17/31

    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 B luein I ta l ics , as the code in color is generated when youdouble click on that particularEVENT Button1_OnClick(EventPtr event) // Event code for Do It button

    {// Return "false" to execute default

    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 Procedurefor 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 inB lueI tal ic .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, selectForm1 Tform, 28. Find the On Open, put your mouse pointer on it and double click. This willdisplay 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;

    }

    Thats all the code that is entered into this program. You can compile the code now, and ifthere 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

    Figure 25 Figure 26

  • 8/14/2019 Beginners Palm Programming

    18/31

    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 variablenamed 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 anywarnings that accrue during the compi le and chose to disregard them or correct them at myown discretion.

    After a successful compile Palmphi will create a file called Example1.rcp this is the programfor your palm which can be ran in the emulator or installed in your palm. When ran in theemulator it will look like images below.

    18

    Figure 29

    Figure 30Figure 28

    Example 2

    This is an enhancement of Example 1 which will automatically adjust the size of the secondvalue 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

  • 8/14/2019 Beginners Palm Programming

    19/31

    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 Formexample1.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 thats all the code. Now Compile it and run it inthe Emulator. The result should be as in Figure 34.

    19

  • 8/14/2019 Beginners Palm Programming

    20/31

    Example 3: Working with Char, StringManipulation, 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 thatwe 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 willinsert a Start Icon that will be displayed as the Icon for this program on your Palm, includea 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 asC:\Palmdev\Work.Then for the Application Name Window type in Example3.Finaly enterPLE2 into the Application ID Window then Click on the OK button to take you back to theEditor Window.

    2. Open the Object Inspector Window Properties as in Figure 35 to display Example3Tapplication. Now enter 1.00 for a Version Number in the appropriate

    Window. As you work with an application and modify it you willprobably want to increase the Version number to reflect improve-

    ments in your program. Next we want to enter a category for thisapplication which will determine in which window on the Palmour program Icon will be displayed in. For this application I havechosen All for the Category window. We could have usedGames, Work, Personal what ever suits your needs.3. Creat ing an Icon: I use Windows Paint forthis although thereare other programsavai lable witchcould do the job.Start Paint and setthe Attributes asin Figure 36 to36

    X 36 This couldalso be 32 X 22 or22 X 22 Pixels,Note ( When using32 X 32 keep the

    lower area of your

    Icon clear as the

    name of your application will be placed there) and Color to Blackand White. Next in the View box set Custom to 600% which willgive you a decent sized work area. Create your Icon as in Figure

    37 . You can create any image you want, that is up to you butfor this Example I kept it simple. Click on the File then selectSave 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 tothe directory you created your application in C:\Palmdev\Work\Example3.

    4. In your Properties Window select Icon then click on theYellow Icon and this will display a directory tree. Point thisto your Icon file as in (C:\Palmdev\Work\Example3\Example3.BMP). There now when you load your program intothe Emulator or your Palm this Icon along with your programname will be displayed on the main screen.

    20

    Figure 35

    Figure 37

    Figure 36

  • 8/14/2019 Beginners Palm Programming

    21/31

    5. Form1 should be displayed on your Editor Window, inthe Properties Window for Form1 change the captionto Example3. Next add three Labels to this form, andfour Edit Boxes, as in Figure 38. In Label1 Captiontype Enter Your Last Name , for Label2.Caption shouldread Enter Your Middle Name., and finaly Label3.

    Caption add Enter Your First Name . Nowyou should position them as in Figure 38 so

    that the text iscentered in thewindow. Thefour Edit Boxesshould havetheir propertiesset as in the ta-ble in Figure 39and positioned as in Figure 38 with Edit4 Showingthree lines.6. Next we need to add two Buttons, as in Figure38. To our Form1. The first Button will be labeledDo It, and the second Button will be labeled Clear.

    7. Alert Box: Click on theTAlert Window to createan Alert Box then set the properties as in Figure40.The Message Window should contain the fol-lowing text- ^1 - this will allow it to handle thethree separate messages . We will leave theTalert name as Alert1 so when we want to call itwe just call Alert1 from our error detection pro-cedure.

    8. The Code: Double click on the Do It Button andenter the code below shown in Blue Bold, The

    Code in Green is generated by Palmphi, and thecode in Gray are commnents which do not affectthe operation of the program lettering.

    Now Double Click on the Clear Button and enter the textin BlueBold Note the Comments are in Gray.

    EVENT Button1_OnClick(EventPtr event)

    {

    // Return "false" to execute default message handling

    StrCopy(Lname,Edit1.Text ());// Below is code for Alert1 and control code. If an Error setto True

    if (alert==StrLen(Lname)) {Alert1.Show("Last Name not Entered Redo");control=1;}

    L=StrLen(Lname);

    StrCopy(Mname,Edit2.Text ());// Another way to detect an error and display Alert and setcontrol to True

    if (Edit2.Length()==*"") {Alert1.Show("Middle Name not Entered Redo");control=1;}

    M=StrLen(Mname);

    StrCopy(Fname,Edit3.Text());

    F=StrLen(Lname);

    if (Edit3.Length()==*"") {Alert1.Show("First Name not Entered Redo");control=1;}

    if (control==0)// If control = True skip next three process then reset control toFalse

    { // If no Errors control = False so do these three lines of c ode and return

    21

    Properties Edit 1 Edit 2 Edit3 Edit4

    Width 80 80 80 140

    Read Only False False False True

    Underlined True True True True

    Multilined False False False True

    MaxChars 20 20 20 0

    AutoShift True True True False

    Numeric False False False False

    Figure 39

    Figure 38

    Figure 40

    ^1 in Message Window as above.

  • 8/14/2019 Beginners Palm Programming

    22/31

    22

    EVENT Bu t ton 2_OnCl i ck (Even t Pt r even t )

    {

    / / R e t u r n "f a l s e " t o e x e c u t e d e f a u l t m e s s a g e h a n d l i n g

    Edit1.Delete(0,L+1);//Now use t o determine length of string to delete

    Edit2.Delete(0,M+1);

    Edit3.Delete(0,F+1);Edit4.Delete(0,Full+1);

    Edit1.SetFocus();// Set Focus to Edit Box 1 after

    deleting all

    r e t u r n t r u e ;

    }

    Enter the following code at the top of the main formForm1.c.Char Lname[40];

    Char Mname[40];

    Char Fname[40];

    Char FullName[120];

    UInt16 F,M,L,Full,alert=0;

    int cont rol=0; //0 = False 1 = True

    In the Object Inspector Window for Events, Doubleclick on the OnOpen frame This will generate the OnOpen Event code shown in BlackItalic below, then enter the code shown in Bold Bluejust as below.

    EVENT Form1_OnOpen(EventPtr event)

    {

    // Return "false" to execute default message handling

    Edit1.SetFocus();//Set Focus to Edit1 when program starts.//Set focus to Edit1 onOpen

    return true;

    }

    10 We are ready to compile our code now, and if all the information was entered correctlyit should compile and create Example3.prc which you can run in the emulator or inyour Palm. Below are pictures of the program running in the Emulator Pose. The Imageto the Left shows the Icon that was created earlier, and the Image to the Right showsthe program running with information entered.

    11 The bottom picture on the left has the middle name omit-ted to create the error message.

  • 8/14/2019 Beginners Palm Programming

    23/31

    23

    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 = TrueEVENT Form1_OnOpen(EventPtr event)

    {// Return "false" to execute default message handlingEdit1.SetFocus();return true;

    }

    EVENT Button1_OnClick(EventPtr event)

    {

    // Return "false" to execute default message handlingStrCopy(Lname,Edit1.Text()); // Below is code for Alert1 and control code. If an Errorset to True

    if (alert==StrLen(Lname)) {Alert1.Show("Last Name not Entered Redo");control=1;}

    L=StrLen(Lname);

    StrCopy(Mname,Edit2.Text()); // Another way to ditect an error and set Alert andcontrol to True

    if (Edit2.Length()==*"") {Alert1.Show("Middle Name not Entered Redo");control=1;}

    M=StrLen(Mname);

    StrCopy(Fname,Edit3.Text());

    F=StrLen(Lname);

    if (Edit3.Length()==*"") {Alert1.Show("First Name not Entered Redo");control=1;}

    if (control==0)// If control = True skip next three process then reset control to

    False{ // If no Errors control = False so do these three lines of code and returnStrPrintF(FullName,"Hello %s Your full name i s\n %s %s %s",Fname,Fname,

    Mname,Lname);

    Full=StrLen(FullName);

    Edit4.Text=FullName;

    }

    control=0;

    return true;

    }

    EVENT Button2_OnClick(EventPtr event)

    {

    // Return "false" to execute default message handlingEdit1.Delete(0,L+1);

    Edit2.Delete(0,M+1);

    Edit3.Delete(0,F+1);

    Edit4.Delete(0,Full+1);

    Edit1.SetFocus();

    return true;

    }

  • 8/14/2019 Beginners Palm Programming

    24/31

    24

    Example 4 Creating a Data Base Similar toMemo

    In this Example I will demonstrate creating a simple Data Base named StuffDBwith three data entry fields. Two of the fields will hold 30 characters of text which can beexpanded needed by just declaring larger values for the character array strings. When Idefined the structure I named the character arrays Fname, and Lname. The names couldbe changed to any name you think is appropriate for your application, The array length forFname should not be changed as this also must be displayed in the list box of form 1 alongwith a number, and if made too long would flow past the right edge of the list box. LNamearray length could be increased to 1,000 if you needed as long as you changed the text boxproperties to multiline and string length to an appropriate value. The edit box for the floatvalue 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 eventsprocedures of the form, this saves a lot of repetitive typing, and also makes it easier to readthe 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 descriptions) read from the data base and storedthere. If you want to increase this so that you can display alarger list increase this by multiples of Fname array lengthexample(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 Iused in this example.

    2. The Form1 properties should be , Save Behind is set atFalse, and Modal is also False.

    3. Next add a list box to Form1 with the properties valuesset as in picture to the right.

    4. Then create a Button and place it in Form1 bellow the listbox, 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 labelsDescription,Details, andFloat .

    7. Create threeEdit Boxes inForm2 with the

    values set as inpicture belowfrom left toright startingwith Edit 1 onthe left.

    8. Near the bot-tom center ofthe Form2 alsoadd a Button

  • 8/14/2019 Beginners Palm Programming

    25/31

    25

    and name it Done.Thats all the object we will be using in this example, You can change the Label names orrename the Buttons to whatever suits your needs. Next comes the code for the program. Ifirst 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 needto search through the entire program searching for the code used to open, close, or writeyour 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, Greenis the code generated from Palmphi, and allcomments 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

    //++++++++++++ Form1.C for MyData Application++++++++++++++++++++++

    //+++++++++++++++++Written by LeRoy Olson +++++++++++++++

    //++++++++++++++++++++++ Feb 11 2004 ++++++++++++++++++++

    //**************** Declare our function's

    static Do_Open();

    static Do_Close();

    static Do_Read();

    static Do_Insert();

    static Do_UpRead();

    static Do_Modify();

    TPalmDB ATestDB; //**** DB Name

    // ******* Define our structure for the DBtypedef struct {

    Char FName[30],LName[30];

    float MNumber;

    } myRec;

    myRec Stuff;

    Int8 Control=true; //control Insert or Modify Data Base. If true = Insert Int16 si=0; //Selected Item used for selecting Item in list boxChar NFN[30],All[900]; //NFN = New First Name, All = Data file for listbox1**

    // ************* Increase for more data 900/60 = 30 records 1800/30 = 60

    static Do_Modify() // ****** Function for Modifying DB{

    ATestDB.Modify(si,&Stuff,sizeof(Stuff));

    }

    static Do_UpRead() // ****** Update read function{

    if(si==ATestDB.RecordCount())

    {

    Edit1.Delete(0,25); // *** Delete old data in Form2.c Edit2.Delete(0,25);

    Edit3.Delete(0,10);

    } else {

  • 8/14/2019 Beginners Palm Programming

    26/31

    26

    ATestDB.Read(si,&Stuff,sizeof(Stuff));

    Edit1.Text=Stuff.FName; // Refresh the data on Form2.cEdit2.Text=Stuff.LName;

    Edit3.AsFloat(2)=Stuff.MNumber;

    }

    }

    static Do_Open() // ***** Open our DB{

    ATestDB.Create("ATestDB",'LTOJ');

    ATestDB.Open("ATestDB",dmModeReadWrite);

    }

    static Do_Close() // **** Close our DB{

    ATestDB.Close();

    }

    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 boxfor (i=0;i

  • 8/14/2019 Beginners Palm Programming

    27/31

    27

    ListBox1.Erase();

    ListBox1.Items=All;

    ListBox1.Draw();

    Do_Open();

    Do_Read();

    Do_Close();

    ListBox1.Erase();ListBox1.Items=All;

    ListBox1.Draw();

    return true;

    }

    EVENT Button1_OnClick(EventPtr event)

    {

    Control=true;

    Form2.PopUp(); return true;

    }

    EVENT ListBox1_OnClick(EventPtr event)

    {

    Int16 i=0,sl=0;

    if(sl=StrLen(ListBox1.SelText())>0) //prevent empty file display{

    Do_Open();

    i=(ATestDB.RecordCount());

    Do_Close();

    if(i>0) {

    Control=false;

    si=ListBox1.ItemIndex();

    //Do_UpRead();

    Form2.PopUp();}

    }

    return false;

    }

    Code for Form2.c

    EVENT Button2_OnClick(EventPtr event)

    {

    if(Edit1.Length()>2)

    {Do_Open();

    StrCopy(Stuff.FName,Edit1.Text());

    StrCopy(Stuff.LName,Edit2.Text());

    Stuff.MNumber=Edit3.AsFloat();

    Edit1.Delete(0,25);

    Edit2.Delete(0,25);

    Edit3.Delete(0,10);

  • 8/14/2019 Beginners Palm Programming

    28/31

    if(Control==true) {Do_Insert();}

    if(Control==false) {Do_Modify();}

    Do_Close();

    }

    Form1.Show();

    Form2.Back();

    return true;

    }

    EVENT Form2_OnOpen(EventPtr event)

    {

    if(Control==false)

    {

    Do_Open();

    Do_UpRead();

    Do_Close();

    }

    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 programworks well and I could not get it to generate an error message, but I did not over flow theAll array which I believe will start giving erroneous readings if you exc eed the characterlength of the array so some logic should be added to prevent it from happening .

    28

  • 8/14/2019 Beginners Palm Programming

    29/31

    Example 5 Using the values returned fromAlert Message For Controling a Program

    This example shows how to get the value returned from an Alert form button pressed anduse 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 anevent 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 textin Gray is only for information for the writer or other people to help them understand thecode. Blue will be the code you will be entering into the form.

    // *************** Getting information from buttons in TAlert// ***************************LeRoy Olson//**************************** Feb 15 2004

    EVENT Button1_OnClick(EventPtr event)

    {

    if(Alert1.Show()==false) // If changed to true the display text will be reversed{

    Edit1.Text="Ok was pressed";

    } else {

    Edit1.Text="Cancel button pressed";}

    return true;

    }

    // Below shows how to use the information returned from TAlert2 to control programEVENT Button2_OnClick(EventPtr event)

    {

    if(Edit2.Length()

  • 8/14/2019 Beginners Palm Programming

    30/31

    {

    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;

    }

    EVENT Edit2_OnEnter(EventPtr event)

    {

    // Return "true" to override default message handlingButton2.Visible=true;

    return false;}

    30

  • 8/14/2019 Beginners Palm Programming

    31/31