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
           



No comments: