Sunday, 29 December 2013

Learn PowerBuilder Quickly - Part -1.3 Application Object Events


Hi everybody

On the last post I have mentioned about 6 events which application objects does have. Today we are going to see briefly about those six events

-----------------------------------------

The six Main events of Application Object are
1.      Open    
2.      Connectionbegin
3.      ConnectionEnd
4.      Close
5.      Idle
6.      SystemError

1. Open
            This is main and very important event in the powerbuilder. Without this event we can’t run any of our application. Whatever the project we are doing and in that project which window should be appear first that information should be coded on here. The first window to opened in the project to and if any database is used in that project means, then we want to mention the DB connection in this open event. 

Ex:
            Open(w_main)
This is the code, to open the w_main window first when the project gets run
Ex.
            SQLCA.DBMS = "OLE DB"
SQLCA.AutoCommit = False
SQLCA.DBParm =  "PROVIDERSTRING='Database=DBNAME;Trusted_connection=yes;', PROVIDER='SQLOLEDB', DATASOURCE='SERVER NAME',DelimitIdentifier='Yes',StaticBind='No'"
CONNECT USING SQLCA;

(DONT GET CONFUSED ABOUT THIS CODE , THIS WILL BE EXPLAINED IN NEXT POST)

This is the code to connect the database.
Now we have know about what should be written on Open Event of the Application Object
In technical terms open event is described as “Occurs when the user starts the application”. 

2. Connectionbegin
            This event is used for specifying the connection parameters that is used to connect the database. We can do this connection at open event also. But this event is the proper place to code the connection parameters. But most of the times developers do coding at open event itself. This event is mainly used in client server applications, where the initial connectivity is done by open event. And later when client tries to access the server this connection begins will be triggered and connection is established. 

This event is technically described as
In a distributed computing environment, occurs on the server when a client establishes a connection to the server by calling the ConnectToServer function.


3. ConnectionEnd
As explained in above, every time a client connects to the server, ConnectionBegin event is fired at the server. When the process is done, then its gets disconnects from the server, so at the time of this process the code returned in the connection End will be get executed.
In real times most of the developers won’t use these Events because of some error handling problems. Instead they will utilize the Open and Close events

This event is technically described as
In a distributed computing environment, occurs on the server when a client disconnects from the server by calling the DisconnectServer function.

4. Close
            This is the most used event in application object. This event is used also for the alternative of ConnectionEnd Event.  When the project work is done , all the process are completed then the used is going to close the project means at the time if we want to do and operations or want to throw any message/information/Error means we can code that codes in this event. Also the database disconnect coding are coded here. We can also prevent the closing of project by UN accidental way by asking the user to confirm the close.

Ex:
IF MessageBox("Closing window", "Are you sure?", Question!, YesNo!) = 2 THEN
   RETURN 1 
ELSE
   RETURN 0
END IF

5. Idle
            The application is started and is in at running stage, if the used not interact with the application for the certain amount of time then we want the application to be got locked, like this kind of scenarios idle event is used.
            If there is no interaction with the application for the particular amount time then the idle event is executed.
Ex:
Idle(300) // Sends an Idle event after 5 minutes.  


6. SystemError
            When the application is at running if any undetermined/uncaught error occurred and that is not handled in coding means then powerbuilder throws and error and exits the application. We can prevent this unexpected error and closing of application by coding on this event and ask the user to close or not. We can use try – catch to implement error handling in this event.

Technically described as
Displays system errors and allows the user to either continue running the application, exit the application, or print the error message. 

Ex:

Messagebox ("Error","errornum"+string(error.number)+ &
                                                            "message"+error.text+ &
                                                            "where"+error.windowmenu+ &
                                                            "object"+error.object+ &
                                                            "event"   +error.objectevent+ &
                                                            "line"+string(error.line))


As for as now we have learned about the application object and events of the application object and when to use which event. Try to do some practicals like last post. We will see at next post.

------------
Regards
Pushparaj
           



Thursday, 26 December 2013

Learn PowerBuilder Quickly - Part -1.2 Working With PowerBuilder

HI everybody
On last post I shared about very basics of powerbuilder. That’s full of theory, if I go on that way then you may feel bore about reading. So let’s we learn by theory cum Practical’s. Hope you have installed PB software in your system. Let’s we do our practicals now.
--------------------------------
Today we will do an simple project to display a message box.
First Open your PB Application.
We can open PB by going to start menu, select powerbuilder . This is one way, we can also open PB by opening Run in Windows, type pb105 [here the number 105 means the version , if you using 12.5 then use pb125].
The window will look like


Fig 1.1

You can have a look on all menu items and all icons in this window.
So that its easy to go to that one quickly.
As we seen yesterday we want to create the workspace first.  For that
                Goto -> File Menu -> New
That will look like this.


Fig 1.2

Now Press OK
It will ask for Workspace name , and the path where to store the Workspace. For our training Purpose , create a Folder with any name and Navigate that to that location and Give the name for the workspace. In my case I have created a new folder at D: Drive with the name Practicals. And the workspace name as pb_practicals.
If you done all these and press ok you will get the PB window like this


Fig 1.3

Hope you get it , no problem in this.
Now we have created a workspace.
The next concept we have studied is Application.
To create an Apllication we can go by
                File-> New         Or   Using Keyboard  CNTRL + N
When you do this you can see the same Figure 1.2 . You see there are 8 tabs in there, The first tab we already used , that’s for Workspace creation .
Now we want to go for Second Tab. When you do this you can see this window.


Fig 1.4
Choose the Application Icon located at first. It has Many Icons, we will discuss this at later.
Now Press ok Button.
You can see this window , give the name to the application
The second text box shows the Library path. The next one is Target . So we are creating , Application , target, library.



Fig 1.5

Have a look at the library path and the target path, its where they are stored. Now press ok
After you did these steps you can see the window like this



Fig 1.6

The next thing we want to create is objects. As read at last post we know about objects. Now we will create a window object. To do again do new , CNTRL + N



Fig 1.7

Now go for 3rd tab, These are the some of the main PB objects.
 in that select the window icon , and press Ok. Now a window is appeared in front of you.
As shown in the below figure move your cursor and select the Command Button


Fig 1.8

Click it and come to window surface and do one more click. Now command button will be placed in your window. By default the name for the command button is none. You can give the name to the command button by select text on the right side or in above. I show you where is those



Fig 1.9

In these two places at any one place you can change the name of the visual object.
 Now we want to do code for the command button. So that when you click on it , that will show a messagebox.  To write code to any visual objects double click of the control , or right click on the control and choose the script option.
And write down the code
Messagebox('Hi Buddy','This is Test Message')
Now we want to save what we have done. To do so , as like normal save do CNTR + S
It will ask for window name to save , and also library,  as far as we have created only one library so now no problem . but in future we are going to work on many libraries on single target , so ensure we are saving the objects at appropriate library.
And while giving the name to the objects We should Follow the Naming Rules. If you not aware of the naming standards Kindly see the Post about Powerbuilder Naming Standards.


Fig 1.10

Now we have done almost 90% of the work in this project. What else want to do???
We didn’t said to powerbuilder that , this is my window , while Runiing you should run this . So where we want to to do so.  Here comes the main thing , the Application Object.
Now close the Window , I mean the Library Window, Return back to the  Library ,got it? Or confusion , well I show what is library,


Fig 1.11

This is the Library Window. To view this can do , go to Tools Menu  ->  Library Painter , or Shortcut Key Shift + F10
Now you can see the Window what we have created.
As I said earlies we want to tell PB to which is opening window. At left side can you see the name of the window that we created , above to that and under pb_practicals.pbl there is one object is there , Every application has a application object , whenever you create a application along with that application object is created. That is the thing where we want to give the initial opening codes.
Lets Double click that

This Apllication object has 6 Events in it
Open    
Close
Connectionbegin
ConnectionEnd
Idle
SystemError
We want to write our code in Open Event

So we have already double clicked the Application object rite. By default it will be in open Event. Lets write this code in there
Open(w_main)

Save it . -> CNTRL + S
That’s all Project Ready. Now we want to Run it, To Do so Use CNTRL + R.
Can you see this window?


Fig 1.12

Click on the Button
Can you see this ??

Fig 1.13
Fine , our First project is over.
Rite now we have created workspace , application Target, library , window object , button.
Do it again for practice about creating these basic things.
Here I have stated very few things. By default PB has a excellent help file. When you press F1 it will display the help window . in that search for the terms what we have studied. And gain extra knowledge . will meet at next post.


--------------------
Regards
Pushparaj


PowerBuilder Naming Standards - Objects , Datatypes , Events, Varialbles

Objects



Prefix
Object Type
a
application
w
window
d or dw
datawindow
m
menu
m
menuitem
f
global function
lf
local function
mf
menu function
s
structure
ls
local structure
uo
user object
uof
user object function
wf
window function
ws
window structure



Controls and Events


Prefix
Control/Event Type
cbx
check box
cb
command button
dw
data window
ddlb
drop down list box
gbx
group box
hsb
horizontal scroll bar
ln
line
lbx
list box
m
menu item
mle
multi line edit field
oval
oval
p
picture
pb
picture button
rb
radio button
rect
rectangle
rrect
round rectangle
sle
single line edit field
st
static text
sd
SDE defined event
ue
user defined event
uo
user object
vsb
vertical scroll bar


























 DataTypes



Prefix
DataType
t
datetime
b
boolean
c
decimal
u
double
d
date
g
Graphicobject
i
integer
l
long
r
real
s
string
t
structure
a
application defined object
x
transaction object
o
BLOB
m
time
w
Window





















 Variables at Different Scopes

Preix
Scope
g
global
s
shared
i
instance
l
local
p
parameter (for datawindows, functions or subroutines)
r
reference parameter to a function
a
structure or object attribute (optional)















These are all the PB Naming Standards .

----------------
Regards
Pushparaj