Welcome to the unofficial GoDB Developer Network.
This blog is completely dedicated to GoDB platform -- a multi platform Mobile RAD tool for developing handheld and wireless applications for Windows Mobile (Pocket PC,Win CE, Smartphones), Palm, Symbian, Embedded Linux, Linux, Win 32, etc.
Fellow GoDB developers can find sample codes, contribute to the blog and Mobility related news for the benefit of the mobile development community as a whole.
Thursday, September 16, 2010
Getting Started
Getting Started With GoDB
GoDB is a Multi-Platform Application Development tool. GoDB lets you develop applications you code once and deploy them to multiple platforms without any change.
GoDB SDK comes with an IDE that lets you create, modify, build, run, simulate, debug and deploy your applications to multiple platforms from familiar Microsoft
Windows.
Loading and Running a sample project
Step 1) Start --> Programs --> GoDB --> GStudio
Step 2) File --> Open
Step 3) Select the Project to load (Sample1)
Samples are located under the GoDB Installation Folder.
In this tutorial we will see how to create a simple Hello World application.
Step 1: Launch GStudio
GStudio is the RAD(Rapid Application Development) IDE(Integrated Development Environment) for developing GoDB applications.
Start Menu->Programs->GoDB->GStudio.
Step2: File->New Project.
Select the Project Type "Hello World Application".
Select the Project Directory by clicking on the button next to "Location".
Enter a Project Name in the "Project Name" box
Select the Platforms for which you want to build this project
Click OK button to create the project
Note: You may add additional platforms to the project any time later.
This should create a project, add some startup files.
Lets look at the files that were created now.
Logon.frm All GoDB projects start with a logon screen so that the user can login before using the application.
Home.frm When the user logs in successfully, this page is loaded.
Config.frm,Config.ini These pages are for viewing and storing configuration information. We will see how to use these pages in detail in later chapters.
Now Lets compile and run the project.
Select the Platform,
Compile.
Run
You Should see the Login Screen in the Simulator
Click on Logon Button.
You Should see the Welcome to GoDB Button.
Close the simulator by clicking on the Power button .
Event handlers in GoDB are GBasic scripts that are invoked when an event on a control is fired.
In the IDE Open home.frm by Double clicking on it in the project tree.
When the form opens up Double click on the "Welcome to GoDB" Button.
This should add a bas file called Home.bas and open up the code editor where you can write GoDB GBasic Scripts.
Type the above code Save, Compile and run the Project. In the simulator when you login and click on the Welcome to GoDB Button you should see a "Hello There" message box.
When a project is compiled all these files are bundled into a single BDB file.
The GoDB VM loads and executes this BDB file.
This BDB file is platform neutral so you can copy a BDB file created on one platform say Win32, copy it to an another
platform say Linux your application should run without any change.
GoDB Achieves Platform neutrality by having separate GoDB VMs for separate platforms.
When you distribute your applications you just need to bundle the BDB file and the GoDB VM for the platform you wish to run the application on.
Any variable that starts with ~ is a global variable and is
accessible from any function, subroutine and from any bas file in the project.
All variables declared outside the subroutines and functions becomes
a page-scope variable. This type of variable is accessible in any function and
subroutine within the same bas file. Variables created in a function or a sub
have a LOCAL scope. They can be accessed only within the function.
Example
Home.Bas
Gnum1=10
'Page Variable - this variable can be accessed only in home.bas file.
~glob=20
'Global Variable - this variable can be accessed in all the .bas files.
sub test1
Lnum1=30
'local variable accessible in test1 sub only
print Gnum1
'gNum1 has PAGE scope, so it can be accessed in test1
print Lnum1
endsub
sub test2
print Gnum1
'OK
print ~glob
'OK
print Lnum1
'ERROR : LNum1 local variable accessible in test1 sub only
endsub
Home2.Bas
sub test3
print ~glob
'OK - if home.bas was loaded first and ~glob was initialized.
print Gnum1
'ERROR : Gnum1 is accessible only in home.bas
print Lnum1
'ERROR : LNum1 local variable accessible in test1 sub in home.bas only
GoDB allows creating modular applications using subroutines and functions.
Subroutines are blocks of code that do not return values.
Functions are blocks of code that return values.
Subroutines are defined as.
SUBSubroutineName(Parameters)
iff condition then return
EndSub
To call a subroutine you have to use the CALL statement.
Ex:
Call test1
End
sub Test1
print "Inside Test "
endsub
Ex Sub with parameters:
Call test1(1,"test")
End
sub Test1(a,b$)
print "Inside Test with numeric and string parameter";a;b$
endsub
Note: You should not jump out of a sub using a goto statement.
Use Return statement if you want to exit a subroutine.
In GoDB when strings are passed to a sub or function,
they are passed by reference. String
literals , String expressions ,
Numeric variables and Numeric Expressions are passed by value. All arrays variables
are passed by reference.
iff a=1 then goto !Cond1 iff a=2 then goto
!Cond2 goto !ENDPROG
!Cond1 print "Cond1" goto
!ENDPROG
!Cond2 print "Cond2"
!ENDPROG
To allow of
jumping based on a variable GoDB supports Label Dereferencing. Using Label
Dereferencing the label can be decided based on a string variable and a
Dereferencing {
operator.
j$="!Cond"+a goto {j$} goto
!ENDPROG
!Cond1 print "Cond1" goto !ENDPROG
!Cond2 print
"Cond2"
!ENDPROG
Similarly you can use Dereferencing
operator to call Subroutines too.
for i=1 to
3 a$="Test"+i call
{a$} next
END
Sub Test1 print
"Test1" EndSub
Sub Test2 print
"Test2" EndSub
Sub Test3 print
"Test3" EndSub
Note: Dereferencing can be done to
Fields, and even Variables.
GStudio comes with a powerful Form builder that lets you design Forms visually. Forms in GoDB are text files with XML tags
that correspond to different controls that GoDB Supports. When you add a text box to the Form a XML tag corresponding to a text box is created.
This section will demonstrate the process of creating a form, dropping controls and creating event handlers.
Step 1) Create a New project
Step 2) Open Home.txt and select the "Welcome to GoDB" button and delete it.
Step 3) Drop three label controls and Change their values to Enter Number 1 , Enter Number 2 and Result.
Step 4) Drop a Button Control, Drop three text controls and empty the value attributes for the text controls.
Step 5) Right click on the Calc Button -> Script Wizard -> On Click.
Alternatively for Click events you can just double Click on the control.
This should open up home.bas with a empty event handler.
Sub Button1_Click
' Add Handler Code Here
End Sub
Add the following Code to the event handler
Sub Button1_Click
#text3=#text1+#text2
End Sub
Compile and run the application. Enter data in the text boxes and hit the button. The third editbox should show the
sum of the numbers entered in the first two edit boxes.
Certain issues remain with this app. First the edit boxes allow characters.
Second the content in the result edit box can be modified. A common way to handle this is to make the edit boxes accept only numeric values and the result box
readonly.Here is how this can be done.
Select the text box and locate the validate property , click on the ... button and select the Numeric Check Box and hit
ok. Repeat this for the second text box too.
Select the third text box and make Disabled attribute to Yes. Alternatively you can also use a Readonly box for the result.
The form builder in GoDB can be used to create Forms that have different layout in different platforms.
The Master Form is common for all the platforms.
To adjust the layout for a different platform just select the appropriate platform tab.
The blue guide line indicates the screen boundaries for the platform.
Here we can see that the form has to be redesigned for palm.
Simply reposition or change the attributes of the controls to suit your platform screen size.
You can see that we have changed the X and Y positions in the Palm Form. This is indicated by the BOLD font in the attribute names.
If you want to remove any attribute you have to do it in the Master page.
When the project is compiled based on the platform selected for compilation the attributes from the appropriate Form will be used.
During the design process sometimes you might want to apply the value of a specific attribute to
all the platforms.This can be done by selecting the attribute in the Property list window and clicking on the A button.
If you want to apply all the attributes in a specific control in a platform to all the platforms you can select the control and Right click
-> Apply to all platforms.
You can also restore the default settings for a control by selecting the control and Right click
-> Revert all to default.
You can remove unwanted platforms by right clicking on the platform tab and selecting Remove Platform.
You can add a new platform you can right clicking on the platform tab and selecting Add Platform.
In the popup just select the platforms you want to add or
remove and hit OK.
The above examples
demonstrated Events that Fields generate, similarly the forms also generate
events that are common to all the controls like Mouse Click etc.
To
Generate Form Event Handlers Right click on the form when no controls are
selected.
>
Form_Load Event is called when the form
is loaded.
Form_Keypress Event is called the
user presses any key.
GetKey() Function can be used to identify the key
pressed. KeyHandled method determines if the events are bubbled to the
next control or not.
Sub Form_KeyPress ' Add Handler
Code Here ' keycode = GetKey() ' KeyHandled(1) End Sub
face=Verdana>Form_MouseClick , Form_MouseUP and Form_MouseMove
Events are generated for mouse events. GetX() and GetY()
functions return the X,Y location of the mouse. face=Verdana>MouseHandled method determines if the events are
bubbled to the next control or not. For Example of a user clicked on a
button Form_MouseClick is called first and if mouse is handled in
this event handler you can choose not to process the Button_Click
Event.
Sub Form_MouseClick ' Add Handler Code Here ' x
= GetMouseX(0) ' y = GetMouseY(0) ' MouseHandled(1) End
Sub
Form_Paint Event is called when
the Microbrowser is painted, All the drawing routines like DrawLine
FillRect etc should be coded here.
Starting with GoDB 3.6 Form_RMouseClick and Form_RMouseUp
Have been added to handle right mouse clicks on platforms that
Add a new form to the project. Right click on project explorer and select Add Form.
In the open dialog enter the name Main.
Select Yes when prompted for creating a file.
Double click on the Main.Frm in the project explorer add a few controls to the form and save.
Now open Home.FRM and add a Link Control . Change the value attribute for this control to
Load Main. Change the URL attribute to !main.frm.
In godb all references to local files should start with a !.
Note: When Changing primary properties use the
Master page. Use the platform pages only for properties that differ from the
Master. This is to avoid errors where you might change a property in PalmOS page
and compile a Pocket PC project and wonder why the property change does not
work.
Alternatively you can just dragdrop a file from the
project explorer on to the form and this will create a link control.