MobileSybase Pocket Builder: Working with DataWindow

Sybase Pocket Builder: Working with DataWindow

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

What is DataWindow?

Many software packages today offer various ways to retrieve and display data from whatever source. In many cases, easy access to data is achieved by a less attractive presentation layer and vice versa. Sybase PocketBuilder gives you a balanced solution that combines the best practices from both approaches. A DataWindow object incorporates business intelligence and different user presentations, so you may show the same data in a number of different ways. By using PocketBuilder’s DataWindow Painter, you can create sophisticated data presentation layouts that will suit your needs in most cases.

DataWindow technology is implemented in two parts:

  • A DataWindow object defines the data source and presentation style for the data.
  • A DataWindow control is a visual container for a DataWindow object. You write code that calls methods of the container to manipulate the DataWindow object.

If you don’t need any visual interface, you can use a DataStore object to manupulate the data. Either way, DataWindow objects allow you to define a data source, track data changes, apply specific valudation rules, and so forth. Presentation styles include tabular, freeform, grid, group, and graph. You also have handy various filtering, sorting, and grouping options. The next sections provide more detail on those topics.

Creating a DataWindow Object

Now, you can create your sample DataWindow object. That’s an easy process. To start with, select File > New > DataWindow tab. The very next step is to choose a presentation style. As noted above, there are five different styles supported in Sybase PocketBuilder:

  • tabular
  • grid
  • freeform
  • group
  • graph

Freeform Style

This style is used to edit a single row or in data entry forms. You can reorganize default layouts, moving columns and text so your form will look as you want. This type of presentation style is often used to show Details of a selected row in the table.

Tabular and Grid Styles

These two styles are similar, and they both allow you to display the data in the way of a table; in other words, multiple rows at a time. The tabular style has headings at the top of the page and data columns under the headings. The grid style looks pretty much the same as a standard spreadsheet. It also allows you to resize columns and rows and reorder columns at runtime without any additional code.

Group Style

This representation style extends the Tabular one by providing a possibility to group data according to a given column. The DataWindow then enables you to define a calculation rule to display data correctly.

Graph Style

According to its name, the Graph style represents the data in many graphical ways (17 different graph types in the current version). You can select All rows to be presented, or only a specified Page. You set up axes where needed, data sets, and so forth. A nice visual representation of your data will be a good compensation for your effort.

Data Sources

You will build your sample based on a Grid-style representation. Thus, after you create a new target, add a DataWindow object and place DataWindow control on main form, you can select a Data Source for it. To avoid dealing with a database at this moment, I select an External Data Source:

A Wizard will request to define fields, their types, and lengths:

Following the Wizard, finally you will see something like this:

In the case of an External Data Source, you have to write some code to fill in the DataWindow control. To make essential example, let’s show all Contacts from Pocket Outlook in our grid. The best place to put your code is the Open method of the main form. Thus, you code the following:

integer li_rc
POOMContact contactArray[]
POOMContact contact
String  sCriteria
DateTime  dt
int idx
POOM poom

poom  = CREATE POOM
li_rc = poom.login()

li_rc = poom.GetContacts( contactArray )

FOR idx=1 to UPPERBOUND(contactArray)
   contact = contactArray[idx]
      dw_1.InsertRow(0)
      dw_1.SetItem(idx,"Name",contact.FirstName)
      dw_1.SetItem(idx,"Surname",contact.LastName)
      dw_1.SetItem(idx,"Salary",Dec(contact.Department))
NEXT

DESTROY poom

This code snippet illustrates the simplicity of PocketBuilder programming. All you have done is just get all Contacts into an array and then iterate through it. As you see, PocketBuilder gives you ready-to-use POOM objects to works with Pocket Outlook with only a few lines of code. The rest of the sample adds and fills in Grid lines in FOR…NEXT loop. The final screenshot is here:

Another way to retrieve external data is to use the ImportClipboard, ImportFile, or ImportString methods of DataWindow object, as in:

dw_1.ImportFile("ExtData.txt")

The following code will prompt you to enter a file name:

string null_str
SetNull(null_str)
dw_1.ImportFile(null_str)

To show various features, I’ve colored the header, changed cell alighments, and so on. You can play around with this simple snipped to investigate another options. Also, you can use data sources other than External; that will be the common case to retrieve data from database in most real cases.

Display Formats and Edit Styles

Different data types you probably need to show up differently. For instance, the person’s name and phone number will not be represented in a similar way. PocketBuilder gives you an opportunity to customize a column’s look-and-feel by specifying Display Format where required. You can do it via DataWindow painter; for example, as follows:

Display Formats are actually masks with special characters. PocketBuilder supports formatting for:

  • Strings
  • Numbers
  • Dates
  • Times

You can declare the mask itself, colors, and also combile several formats. In this sample, I have defined 10 characters in RED to be displayed for the very first column:

Here is the same sample but with the [Currency] format for the last column:

Let me say a few words about Edit Styles. You can choose from:

  • Edit Box
  • EditMask
  • DropDownListBox
  • DropDownDataWindow
  • CheckBox
  • RadioButtons

and customize your data input fields in various sophisticated ways. PocketBuilder’s documentation provides more information.

Validation Rules

Every column in DataWindow object may be given a validation rule. You can do it either in painter or at runtime in a script. The next snippet shows setting a validation rule at runtime:

dw_1.SetValidate( "Salary", "Dec(GetText( )) < 20000")

If the user violates this rule, in the simplest case the following error message will be thrown:

You also have an option to customize an error message.

SetValidate method has several forms, but for every one of them you may define a required validation rule. You can create your own rule, if needed.

Conclusion

In this article, you have learned about the DataWindow objects and touched different aspects of their functioning. You can use DataWindow technology to create powerful applications quickly and easily. The PocketBuilder documentation provides much more detail on what you have just seen. The next several articles will guide you through more topics of PocketBuilder programming.

Download the Code

You can download the code that accompanies this article here.

About the Author

Alex Gusev started to play with mainframes at the end of the 1980s, using Pascal and REXX, but soon switched to C/C++ and Java on different platforms. When mobile PDAs seriously rose their heads in the IT market, Alex did it too. Now, he works at an international retail software company as a team leader of the Mobile R department, making programmers’ lives in the mobile jungles a little bit simpler.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories