Thursday, February 16, 2012

Powerbuilder Datastore

Basicly, DataStore is a nonvisual DataWindow control.

DataStores act just like DataWindow controls except that many of the visual properties associated with DataWindow controls do not apply to DataStores. However, because you can print DataStores, PowerBuilder provides some events and functions for DataStores that pertain to the visual presentation of the data.

Why and when DataStore is used?
We use the datastore, if we want to work with the data in datawindow, but only at the background. User doesn't need to see the data itself. Yes, indeed, we can use datawindow also to do that, with disable in the visible property. But, it's mean you need to insert the database control on your application, and also means that the control will always in the memory as long as the application is running. With the datastore, you just need to create the control when is needed, and can be destroyed when no longer needed.

Creating Datastore
First of all, you need the datawindow object. Create the datawindow object, and named as "d_mydatawindow".

1:  // declare the variable  
2:  DataStore dsMyDataStore  
4:  // create the control  
5:  dsMyDataStore = Create DataStore  
7:  // assign the datawindow object to datastore  
8:  dsMyDataStore.DataObject = "d_mydatawindow"  
10:  // bind the data  
11:  dsMyDataStore.SetTransObject(SQLCA)  
12:  dsMyDataStore.Retrieve()  
14:  // script to process the datastore control, same treatment like datawindow control except the visual functions or properties.  
15:  .....  
17:  // destroy datastore  
18:  DESTROY myDataStore  

Wednesday, February 15, 2012

How to get screen resolution with Powerbuilder

This is the "old" trick, to get the screen resolution.

I'm using Powerbuilder reserved function, call GetEnvironment, which it can be used for another purpose beside screen resolution.

First of all, we must create a ENVIRONMENT variable like below
1:  environment myEnv  

Then we use GetEnvironment function to get the data(s).
1:  GetEnvironment(myEnv)  

Finally, we retrieve all the Environment objects, depending what kind of information do you need. For this case, I want to show how to get the screen resolution:

1:  messagebox("Screen Resolution",String(myEnv.ScreenWidth) + "x" + String(myEnv.ScreenHeight))  

For the complete Environment Object, you can search the Powerbuilder Help, or see the list below.

Environment property Datatype Description
CharSet CharSet (enumerated) The international character set used by PowerBuilder. Values include:
  • CharSetAnsi!
  • CharSetUnicode!
  • CharSetDBCS!
  • CharSetDBCSJapanese!
The values CharSetAnsiArabic! and CharSetAnsiHebrew! are not valid choices in PowerBuilder 6 or later.

ClassDefinition PowerObject An object of type PowerObject containing information about the class definition of the object or control.

CPUType CPUTypes (enumerated) The type of CPU. For a complete list of CPUTypes values, see the Enumerated tab of the Browser.

Language LanguageID
Specifies the value of the language setting for the machine. For a complete list of LanguageID values, see the Enumerated tab of the Browser.

MachineCode Boolean Specifies whether the application executable is machine code (compiled). Values are:
  • TRUE – Executable is machine code.
  • FALSE – Executable is not machine code (pseudo-code).
OSFixesRevision Integer The maintenance version of the operating system.

OSMajorRevision Integer The major version of the operating system. For example, this value would be 4 for Windows 95, 98, ME, and NT 4.x, 5 for Windows 2000, XP, or 2003, and 6 for Vista, Windows Server 2008, and Windows 7.

OSMinorRevision Integer The point release of the operating system. For example, this value would be 0 for Windows Server 2008 and Vista, 1 for Windows XP or Windows 7, 2 for Windows Server 2003 and 64-bit XP, and 10 for SunOS 5.10 (Solaris 10).

PBBuildNumber Integer The build number of this version of PowerBuilder.

PBFixesRevision Integer The maintenance version of PowerBuilder.

PBMajorRevision Integer The major version of PowerBuilder.

PBMinorRevision Integer The point release of PowerBuilder.

NumberOfColors LongLong Number of colors on the screen.

ScreenHeight Long Height of the screen in pixels.

ScreenWidth Long Width of the screen in pixels.

OSType OSTypes (enumerated) Operating system or environment. For a complete list of OSType values, see the Enumerated tab of the Browser.

PBType PBTypes (enumerated) Version of the PowerBuilder product. For a complete list of PBType values, see the Enumerated tab of the Browser.

Win16 (obsolete) Boolean Indicates the type of the operating system in which the application executable is running. Values are:
  • TRUE – Executable is running under a 16-bit operating system.
  • FALSE – Executable is running under a 32-bit operating system.

Wednesday, February 1, 2012

Working with PBR file

When you create or build an application, sometimes you need to add external resource like image, sound or even non standard font.

In Powerbuilder, you have 2 options when you have external resource files.

  1. You always have to copy all the external resource files (*.bmp, *.jpg, *.wav etc) into the client computer, as well as concurrent when you copy your application (*.exe , *.dll files).
  2. You combine all the necessary external files into your application, so you no longer need to copy the files.

The first option has some minus points, example: user can delete by themself the external files. The application may still running, but in some parts, the image will blank.

The second option is not without value minus. The consequence is the application file will be very large. But it would be safer because at least the user can not arbitrarily remove its files.

To implement the second option, Sybase has provided a facility to handle this problem. By using the PBR (Powerbuilder Resource) file, we can put all the file names, along with a complete path, into the application.

Make a PBR file using the Edit menu, and save the file name with extention PBR.

Do not forget to include it in the PBR file in your project, in the Resource file name.

Put your PBR file in your project

All files listed in the PBR list, will automatically be compiled and incorporated into the application file, so you no longer need to copy it to every computer user.