December 18, 2014
Hot Topics:

Sybase Pocket Builder: Working with DataWindow

  • March 28, 2006
  • By Alex Gusev
  • Send Email »
  • More Articles »

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:



Click here for a larger image.

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.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel