Lesson 3
Lesson 3
Multiplatform Form Builder and Event Handlers
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.
Ex:
<TEXT NAME="USERNAME" VALUE="012345678"/>
GoDB Supports the following Controls.
A quick summary of the widgets
Label | Used to Display Labels. | |
Text | Edit Box for capturing Data From the user. | |
Password | Edit Box for capturing Password From the user. | |
Radio | Radio Button. Controls with the same name are grouped. | |
Check | Check Box. | |
Button | Standard Button | |
Image | ||
Frame box | Used to group controls. | |
Link | Used to Navigate between pages. URL property determines the new page. | |
Read Only | Readonly box for displaying results etc. | |
Popup Box | Popup to display help and alert Messages. | |
Script | To Associate a different Bas File to the form. |
Divider | To Display a Divider between controls | |
Poly Line | Special control to display polygons. | |
Title Text | To set the title for the form. |
MultiLine | Edit Box for capturing Multiline Data From the user. | |
List Box | DropDown List box. |
Data Related and Special Controls
Look Up Table (LUT) | Used to Display a Popup to select master items
like Products,Customers etc. | |
Embedded Grid | Grid that can be embedded in a form. | |
Calculator Box | Popup calculator Control for entering numeric data and calculations. | |
Date | Popup Datebox Control to select date. | |
Sign Box | Popup Sign box control to capture Signature. | |
Grid | Full screen grid to display reports etc. |
Hidden | Hidden box for holding temporary values. | |
Submit Button | To Submit the values of a form to an internet site or to another page. | |
Cancel Button | To Clear the values entered in a form. |
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.
GStudio has a powerful built in debugger with break points, watch points etc. Lets see how a program can be
debugged using GStudio.
Copy the following code and paste it in home.bas
i=10
j=20
end
Sub Button1_Click
dim lvar
lvar=10
#text3=#text1+#text2
print i
print lvar
End Sub
You can set a Breakpoint by clicking on the left margin or pressing F9 key.
Now Compile the project and click on Start Debug.
This will launch the simulator in debug mode. When you login you should be able to see the Program Trace, That is the Blue markers in the Left Margin.
Now Click on the Button in the simulator.
This should stop the execution at the break point.
You can see the variables and fields in the Watch Window.
When the Execution is suspended by a break point you can use the debug aids to Control the execution.
Click on to "Step Into" a Call Statement
Click on to "Step Over" a Call Statement
Click on to "Step out" of a Subroutine
Click on to execute till the current cursor position
Click on to Continue Execution from the current break point
Click on to Stop the Debug session
Click on to Restart the Debug Session
To reset a breakpoint simply click on the red dot using your mouse or press F9 key.
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
support it.
GoDB uses a microbrowser for rendering forms,
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.
Compile and run the project.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home