ActiveX Code Components
ActiveX Code Components earlier
referred to as OLE automation Servers, provide libraries of reusable
objects. For example: A code component
can include a library of specialized financial functions for spreadsheets
users, or user-interface elements, like dialog boxes, that are common to multiple
applications. An object in a code
component can run in the same process as our application, allowing faster
access to the object.
In Visual Basic we can build code
components that are in-process or our-of-process. It provides project templates to create each
type of components.
Creating An ActiveX DLL
To begin creating an ActiveX DLL
we double click on the ActiveX DLL Icon in New Project dialog box. It opens a class module ‘Class1’. By changing its name ‘TrialDL’ in General Declaration
Section of Code window a code can be written.
Example1
Private Var As String
Public Sub Greet ( )
MsgBox “Hello” & Var &
“!”
End Sub
Public Property Let MyName (Name
As String)
Var = UCase(Name)
End Property
Public Property Get Message ( )
Message = “This is a DLL Example”
End Property
To register DLL before calling
it, the ‘Make TrialDLL.dll’ option is selected from File Menu. So after adding Standard EXE Project, in
Project Explorer, we have to set reference to TrialDLL to Form1 by selecting ‘
TrialDLL’ from references dialog box of Project Menu.
On the form place Text box and
Button and write following code.
à Private Sub Display_Click ( )
Dim
Obj As TrialDLL.Class1
Dim
StrMessage As String
Set
Obj = New Class1
Obj.MyName
= Text1.Text
Obj.Greet
StrMessage =
Obj.Message
MsgBox
StrMessage, , “DLL”
End Sub
An instance of the DLL is created
using New keyword. Name entered in Text
Box is passed to Name property of the DLL, which converts it into Upper Case
and displays message box with name in Upper Case.
StrMessage variable retrieves
message from the DLL and displays it in the message box.
The Instancing Property
Instancing property of a class
specifies whether we can create an object of a public class outside a project,
and if so, how it will behave. This
property is not available at run time.
Setting of this property are as
shown under:-
1)
Public Not
Creatable
If a component
creates the objects first, only then, can applications use objects of this
class.
2)
Multi Use
Allows other
applications to create objects from the class.
One instance of our component can provide any number of objects created
in this fashion.
3)
Single Use
Allows other
application to create objects from the class, but every object of this class
that a client creates starts a new instance of our component.
An ActiveX Document
An ActiveX Document has a dual
nature. It is a program that users can
use to run all kinds of tasks from simple calculations to accessing databases
across the network.
These documents have all features
of a word document in the fact they can not stand alone. i.e. they can be viewed in a container that
supports them, for example Microsoft’s Internet Explorer.
Advantages of ActiveX Documents
1)
ActiveX Documents support Hyperlink object which allows
to navigate from one document to another.
2)
ActiveX Document can be debugged using debugging tools
of Visual Basic.
3)
ActiveX Documents retain data between sessions as data
is stored through the PropertyBag object.
4)
As an ActiveX Document is loaded in a browser, Menu of
the document merges with that of the browser.
User Document Object
An ActiveX document created with
Visual Basic is always composed of User Document Object, code, code modules,
and controls that we place on User Document.
To use an ActiveX Document we need to place it in a container that
supports it.
Process of connecting ActoveX
Document to it’s container is called “Siting”. This plays a key role in determining event
behavior of the ActiveX Document.
Properties of User Document Object
Hyperlink
It sets the reference to
Hyperlink object. Using methods of
Hyperlink object, an ActiveX Document can request a container that is aware of
hyperlinks like Microsoft Internet Explorer, to jump to a given URL which
identifies full path of a document, graphic, or other file on the Internet. Hyperlink object supports three methods which
enable navigation in a browser.
Ø
Go back : Executes a jump Back in the History
List.
Ø
Go
forward: Executes a jump forward in
the History List.
Ø
Navigate
to: Execute a jump to the specified
target
Events of User Document Object
Following are the User document
objects in detail.
1)
Init
Properties
Allows to
initialize a new instance of the object.
It occurs only when a new instance of an object is being created. This is to allow the author of the object to
distinguish between creating new instance of the object and loading an old
instance of the object.
2)
Initialize
Occurs when
application creates an instance of an ActiveX Document.
3)
Read
Properties
Occurs when we
retrieve a property from PropertyBag Object.
4)
Terminate
Occurs when all
references to an instance of an ActiveX Document are removed from memory by
setting all variables that refer to object to Nothing or when the last
reference to object fails out of scope.
5)
Show
This event is
triggered either when the user opens a sited document in its container or when
he clicks the Back or Forward Buttons to navigate to the documents in History
List of the container.
6)
Hide
Occurs when
user navigates away from current document or when container is closed before
the document is closed.
Methods of User Document Object
The methods of the User Document
object are as follows:
Property Changed
Notifies the container that
property’s value has been changed.
Files of an ActiveX Document
Like Visual Basic forms User
Document Objects have code modules and Visual Designers objects and User
Document objects are stored in plain text files containing source code and
property values of User Document and controls placed on it. Visual Basic uses extension .DOB for these
source files
If User document contains
controls that uses graphical elements which can not be stored as a plain Text
like (Bitmaps) Visual Basic stores them in a .DOX file. Thus .DOB and .DOX files completely define an
ActiveX Document’s appearance and interface.
A compiled ActiveX Document will then consist of either an ActiveX .EXE
or .DLL and an accompanying .VBD file.
In a browser, User must navigate to the .VBD file to open ActiveX
Document.
Compiled files
Visual Basic creates a Visual
Document file having extension .VBD. When
user compile an .EXE or .DLL file the .VBD file will be placed in same
directory as the compiled component.
ActiveX Document Creation
First select ActiveX document Exe
in New Project dialog box. New project starts a User Document object. We click User Document folder in Project
Window and double click on User document object to display it. After User Document object is open, place
controls on it.
Except the OLE container control
we can place any control on the document and then after placing controls on the
document code can be written to handle any task from the document including
reading or writing data in files or accessing a database.
Internet Applications
It is an interactive, compiled
application that can be accessed through a corporate intranet or through the
internet.
HTML (Hypertext MarkUp Language)
is formatting language of the WEB. It is
not a programming and does not support variables. The purpose of HTML is to provide
instructions to web browsers on how to display the files that they download. A .HTM file is used for this purpose.
In Visual Basic Internet
Applications, content can be added to web pages. Visual Basic code can be linked to one or
more HTML pages and events raised in these pages can be effectively handled by
interacting with programs on either the client or the server. There are two main types of Visual Basic
internet applications.
1)
IIS
(Internet Information Server)
Resides on a
Web Server and used to process incoming requests from a browser. IIS Applications process the requests, run
associated Visual Basic Code and return responses to the users. All processing is happens on the Server.
2)
DHTML
(Dynamic Hypertext Mark Up Language)
Most processing
in a DHTML application happens on the browser computer, although the application
can make calls to the server if necessary.
Introduction to DHTML
With the help of DHTML we can
create interactive Web Pages depending on the user actions and requests. Visual Basic provides a way to create DHTML
applications quickly and easily.
A DHTML application is a group of
HTML pages that work together to perform a process. It enables to write Visual Basic Code to
respond to actions on a HTML page, without transferring processing to the
server.
HTML pages can be created with
Visual Basic through the DHTML Application.
Most of the processing associated
with a DHTML application occurs on the client computer, although application
can make calls to the server.
In DHTML application, browser can
process user data, make changes to page’s layout and appearance and process
code without the additional contact to the server.
Creating DHTML Application
Select DHTML application from New
Project dialog box. Project starts with
single page designer and code module.
Open the page designer by selecting it in Project Window. Page designer displays two panes left and
right. Body element is displayed when
document item is selected in design window.
The body element specifies beginning and end of a document and has an ID
associated with it.
Top
No comments:
Post a Comment