Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
34 views
12 pages
OLE Full Concept
ole
Uploaded by
Karthika. N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save OLE Full Concept For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
34 views
12 pages
OLE Full Concept
ole
Uploaded by
Karthika. N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save OLE Full Concept For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 12
Search
Fullscreen
his chapter discusses the OLE (Object linking and Embedding) concepts in detail which TF inctudes ‘OLE fundamentals, OLE automation, and OLE container control. objectives ; O OLE Fundamentals ©} Using OLE Container Control ©} Using OLE Automation Objects © OLE Drag and Drop 8.1 INTRODUCTION ‘An important feature of the Microsoft Windows Operating system is its ability for sharing temp tjon among applications. OLE is a means of communication, which gives any applica~ tion the power to directly use and manipulate other Windows applications. OLE is an impor- tant Windows topic available in Visual Basic. Any object that supports OLE can be linked. OLE specification permits the user to link and embed objects and also edit the object within the container application. This chapter covers the basics of using other applications’ objects in Visual Basic, featuring OLE container control and OLE automation. 82 OLE FUNDAMENTALS DDE is an acronym for Dynamic Data Exchange. It is the basic foundation for inter process communication between applications. In DDE, the application creating a link is known as the destination application, and the application that responds is the source application. Al- though there are functional similarities between OLE and DDE, there are a few differences. While using DDE, unformatted data is exchanged. The Visual basic application has to for- mat it appropriately. For e.g., in ease of an Excel Spreadsheet, the formula used for calculat- ing the result is not fetched, only the resultant number is fetched. *SSEAsSeseh Eee ceecrereaaas: OLE actually transfers control to the original application OLE is a teen Oey, oe en bles the programmer of a Windows-based application to create 2 application that can dis- play data from many different applications. This ‘enables the user to ot i from within the application in which it was created. When a spreadsheet © ee Basic program, the original application is called. OLE contains te correct undesiving ob- jects so the information is fully editable, The following terms and concepts are the funda- mentals for understanding the methodology to use OLE in Visual Basic Objects and Classes unit. It can be a piece of An object is a combination of code and data that can be created as X application, like a control or Form, An application can also be an object. A class defines each object in Visual Basic. An object refers to a discrete unit of data supplied by an Udertaarrhie An application can expose several types of objects. For ‘example, a spreadsheet application can expose a worksheet, macro sheet, chart, all as different types of cell, or range of cells, objects. There are three ways of creating an object in Visual Basic. © ‘The object is added to the Toolbox using the Custom Controls menu and it is drawn directly on a Form. This technique embe interface of a Form in our application. . dee * The CreateObject or GetObject functions can be used for creating the object in code. This technique creates the object in a running instance of the application that provides the object. « The object can be embedded or linked within an OLE container control. This technique permits the change of objects on the Form. At runtime, linked objects have to be created, and the OLE container control has to be bound to a Data control. The application that provides the object’s data and the type of data the object contains Jeterwines the object's class, A class defines each object in Visual Basic. The following statements differentiate between an object and its class. The controls in the toolbox in Visual Basic represent a class. This object known as a control does not exist until it is placed on a Form. When a control is created a copy or instance of the control class is created. This instance of the class is the object that is referenced to an application. « The Form we work with during design time is a class. During run time Vi: creates an instance of a class. command on the Tools ds the object within the sual Basic OLE Automation ‘Some applications provide objects that support OLE automation. We can use Vi i e ° t . We. e Visual Basic to manipulate the data in these objects by programming. Some objects that support OLE eats mation also support linking and embedding. If an object in an OLE container control sup- ports OLE automation, we can access its properties and methods using the Object property Container Application ‘An application that receives and displays an object's data i ; ei éxample, a Visual Basic application that uses an OLE cotitdinar ohare tao eppleation, For from another application is a container application. embed or link data.7 Object Linking and & Linked Objects “sig pata associated with a linked object is Atored hy the application stores only link reference thee Aiaptee 2PMeation that a When we link 7 object, ANY application containing a met Of the souree data jects data and change it. For example, if we lig B Lext Ale 4 that Object can acces the te ext file can be modified by any Application linked to it Ve (4 Visual Basle application, the gocuments linked Co thin text file. We can uke the 61 ‘The modified version Appenre iy all ct in our Visual Baste application © OLE, container eanteot " (4 create @ linked Embedded Objects: When an embedded object is ¢1 Teated, all the dat e object, For example, if a spreadsheet in an embeded ob with that object ia contained in the cells would be contained in the OLE contin” shored ner control or insertable obj pate mith ccoseary formulae. The name of the application thon created the object aes vith e data. If we select an embedded object while working with the Visual Basie » plication, spreadsheet application can be started automatically me thet en can edit thowe call When an object is embedded in an application, no other application hi he embedded object. We can use embedded ol be : ais access to the data in b t jects when we want the application to ont aintain data that is produced and edited in another application, te : 'Pplied the object, Thig State True or False 1. Data associated with the embedded obje 2. SetObject method creates object in code. ——~@ ‘ct is stored by the application supplied. | Ee e as oe 83 USING OLE CONTAINER CONTROL The OLE container control allows adding objects from other applications)(An OLE cuatrol can have only one object at a time. Using OLE control we can do the following * Create a placeholder in our application for an object. Create a linked object in our application. Bind the OLE container control to a database. ; Create objects from the data that was copied onto the clipboard. Display objects as icons. : Perform Po action if the user moves, sizes or updates the objects in the OLE control. Provide backward compatibility with an application that includes many OLE container controls, Creating Objects at Design Time shown Each ti 1 is drawn on a Form, an Insert Object dialog box appears as show in Fig. 81 Sick peosoata a list of the available objects that ean be linked to ar embeded in the application. When an object is inserted into the OLE control at design tinie, ,340 Visual Basic 6.0 Programming i SourceDoc and Sourceltem properties that identify the application ee eee the source filename and any specific file that is linked from within that fi ee ly set. The following example creates a linked object using Insert Object dialog Dox - Example 8.1 © This example creates a link from an existing application. ‘ ° An OLE control is drawn on the Form, ‘This displays an Insert Object dialog pox: * The Create from File option is clicked and the Browse button is chosen. A Browse dialog box appears. * The desired file is selected from the directory an‘ Object dialog box is displayed again .The Link CheckBox is sel is clicked. When a linked object is ereated, the data displayed in the OLB control exists in one place, plication and saved. The which is the source file. The file can be edited in its original ap} ‘ ry object’s data can be accessed from any of the other applications that contain links to that data and the data in the source file can be changed from within any application. (see Fig. 8.1.) . d the OK button is clicked. The Insert lected and the OK button Insetts the contents of the file as an object into “Vout document sa that you mey activate using hich created it \ Fig. 8.4 To Create an Embedded Object at Design Time Example 8.2 ; ‘« An OLE control is drawn on the Form. This displays an Insert Object dialog box. « The Create from File option is clicked and the Browse button is chosen. A Browse dialog box appears.Ss Object Linking and Embedding 2 » The obje desired file is selected from the direct is cli “t dialog box returns. The OK tet OK button is clicked, The Insert -mbedded object is created, i When an embet ij d, we can either embed data from a fil pty object that can be filled later with data, When the data is mbedded from ‘fe pat omy Spied files data is displayed in ho OLE container contr, When a new ebjct ts created, the application that created the object is invoked and data can be entered into the abject. example 83 ifrsis example creates a new file using OLE container. 1 is drawn on the Form. Insert dialog box is displayed at this point of time- OLE contro) 5 Create New option is chosen and Microsoft Excel Worksheet is selected from the list of gptions displayed as shown in Fig 82. «Now right click on the OLE container and choose open. « his takes us to the Excel application. .d are entered in the excel worksheet a ° 8 oe require nd the file is saved as “student. ge eres fedia Clip Mediaview 1.41k Control Microsoft Clip Gallery Microsoft Equation 3.0 Microsoft Excel Chart "| Microsolt Excel Worksheet ‘oft Graph $7 Chatt Ls Fig. 8.2 Special Dialog Box object during design time. This dialog box agraph from a word document, Creating Objects Using Paste Paste Special Dialog box can be used to create an is useful if only a portion of a file is to be ‘used. For e.g., 2 par ora range of cells from an Excel Spreadsheet. Example 8.4 «An Exeel worksheet containing data that is to be linked or embedded is opened. The desired data is selected from the sheet.Wesel Basie 6.0 Programming ve Copy command is chosen © From the Edn man the Cope ee asic Ferm i clicked with the sight mouse botten coe ee pcctal command is chosen from the popup menu, It display a Parte god the Paste Special coma " ‘ won ae shown in Pig, 8.3 Special Wieleg oe ot ee fox cresting an embedded objoct and Paste Link option (ee Whe hove cxample creates an object from an Excel Worksheet and pastes data from row fle res $4 and from column 1 to 7 Ls Fig. 8.3 Creating Objects at Run Time ‘To create & Enked or embedded object at run time, various methods and properties are used i& the cade We can create a linked object at run time using the SourceDoe property and Createlink methed The following code fragment creates a linked object at run time. (As- sume that we have a file called olexla). RED Crestetink *C:\OLE.x15" Creating an Empty Embedded Object at Run Time Tee CresteRmbed method can be used to specify an empty embedded object at run time. The following code fragment inserts a file template for a Microsoft Excel Worksheet in the OLE container control. OLEL.Createinbes **, “Cace) »sheer* om lenin ude creates an empty embedded object and the application is created using OLES.Createimbed **, ‘Excel sheers OLEI.Doverb -5se Object Linking and Embedding oe anacrt Object dialog box can be dis : he Insert Object ¢ be displayed at run time, with whic c variety of ober ent bed usell in document-centered applications ena te wer a wrt a from diferent applications to éreaie a single document. The TawertObj Ig es ets sed to display the Insert Object dialog box. The fallow rbiDg na ¢ following code fragment displays » consider an OLE control and a CommandButton are added to a F i Core is entered in the Commandi_Click) procedure Oe ee private Sub Conmandl_Click() OLEL. InsertObjD1g Tf OLEL.OLEType = vbOLENone Then MsgBox "Object not created" End If end Sub once the aialog box is displayed, the user ean make a choice from the options that are digpinyed. I the user cancels the dialog, an object is not created. the uses selects a choice, a er ted object is displayed. Any changes made to the object can be updated in the OLE ine nol by choosing Update from the File menu in that object. nro c application is chosen to be linked, itis nevessary to check the application is running, To check if the application is running, the following code (OLEL.AppIsRunning) is used. Moving or Sizing the OLE Container The OLE container control has an ObjectMove event, which is triggered when the object associated with the control is moved or resized. An ObjectMove event occurs when the user moves or resizes the object contained in the OLE container control. The arguments of the ObjectMove represent the coordinates of the object within the object’s container. ‘The follow ing example illustrates this. . Example 8.5 * An OLE control is added to OLE1_ObjectMove( ) procedure. private Sub OLE1 ObjectMove(Left As Singles Top As Single, Width As Single, Height As Single) OLEL.Move OLE1.Top, OLEl.Left, width, Height OLEL.Move Top, Left, OLEL-Width, OLEL.Hei ght End Sub a Form. The following code is entered in ttmmctbuade of prngrennrrrem = usind OLE AUTOMATION onsectTs dard technology that applications use to expose their ny languages. and other applications that support sheet application May expore a workaheet, chart, word processor might expose objects -nt, paragraph, sentence, bookmark or selection. ‘Wher as: applination oul tion, the objecta it exposes can be accessed by Viewal Basic. Vieoal Basic could be used to manipulate these objects by invoking methods on she objet ot by getting and selting the object's properties. For example, if we create an OLE. katummasten syed named MyObj, the following code could be written for manipulating the yet sumny.tngert "ello, world.” * Place text. ying Bele + Tree * Format text. *C:\woRDPROC\DOCS\TESTOBJ .DOC” * Save the object. wydiny Ft TeSaweks ‘The saiiowing functions are used to access an OLE Automation object. creates a new object of a specified type. © CreateOpect ¢ GenDiipect retrieves an object from a file. Rafevencing an Object Using an Object Library ‘The chjects, Fenetions, properties and methods supported by an application are usually de few im the application's object library, Every application that supports OLE automatio: type of object. For example, a word processing application may provid provides af Seast ome 2 spgbicetion object, a document object, and a toolbar object. ‘To create an OLE Automatio pe scala the object returned by CreateObject to an object variable which is shown a Dim wordasicdnject As Object Set WorsBesictdject = CreateObject (*Word.Basic*) c = this code : ee Be application creating the object is started (Microsoft Wort a eel oiee ae is already running, a new instance of the application i: rier pereentwsirvgrtaban denen type is created. Once an object is created, we referenct food Sica Te nave defined. In the above example, we access proper methods using the object variable, WordBasicObject, For exampl: WordBasicObject.filenew WordBasicObject.lnsert ‘Hello, world.* WordBasicObject FilePrint 7 “a ot OLE adjeets OLE Antemation el, or tence of elle all ath ax agaention, dovame pports OLE Automal Astametion as an indaclty stan! development toole, mac For example, 9 epread8.5 OLE DRAG anp/DROP OLE drag and drop is a more versatile kind of drag and drop. OLE drag and drop method is only used when we move a file in explorer from one directory (or drive) to another. OLE Drag and drop involves several methods and events, which are dealt with, in this section. OLEDrag Method This method is used to initiate an OLE drag operation. The OLEDrag Method is called when data is copied between two OLE containers. The following syntax is used object . OLEDrag where object is the OLE container object that acts as the source for the drag operation. OLEDragMode Property This property is used to determine if the object can act as an OLE drag source, and if the OLEDrag operation is done manually or automatically. The allowable property values are vbOLEDragManual-0 This is the default value. It is used when the user’s own OLE drag handlers are used in the application. vb OLED rag Automatic-1 This is used when the application has to handle the drag and drop operations.Objaot Linking and Embedding (BAF odeProperty the methodolog no following vale: of processing OL drop event in the application the dofuale value, Ie provents the OM container fron allows bOLEDrop. Automatic-I This T when Che usor ontrusts Visual Basie with handling fhe OLE drag routines, oLeDropAllowed Property operty determines whether the OLE drop operations are allowed or not, If this is set allows OLE drop operations on the container, atherwise drop operations are pro- to True. it hibited. OLEDragDropO event qhis event is fired whenever an OLE drop operation hich allows OLE drop operations. ‘The syntax of tl performed on an OLE container is event is as follows Private Sub object_OLEDragDrop(data as DataObject, effect As Long, button as Integer, shift as Integer, x As Single, y As Single) OLE DataObject can be referenced using the GetData method to retrieve the data being dropped in this event. Effect parameter is used to communicate to the target component the action that is to be performed on the data. The effect parameter can be any one of the follow- ing as shown in Table 8.1. Table 8.1 Parameter Description vbDropEffectNone — 0 ‘Target cannot accept OLE data vbDropEffectCopy — 1 Specifies that data should be copied from source to destination vbDropEffectMove -2 Specifies that data must be moved from source to destination . vbDropEffectScroll Indicates if the target has scrolled, or would scroll if the ~ 2147483648 data were dropped onto it. Used rarely ‘The button parameter is used to identify the button on the mouse that was clicked during OLE drag operations. (see Table 8.2.) 3 Table 8.2 Value Description 1 Left button ~ 3 5 Right button. Middle buttonfe the current position of the mouse pointer. These values .quired within the target control. 348) Visual Basic 6.0 Programming ‘The x and y parameters indicat are used if precision dropping is re Events Related to OLE Drag and Drop i has been dropped from the source control teDrag() event is fired when data d ; aad tt hes tither successfully performed a Move or Copy operation or the operation was is is the final event to be called in an OLE Drag Drop operation. : er meean Sica is fired when the source control's OLEDragMode property is set to manual. It is also fired when the source component initiates an OLE drag operation and LEDragMode property is set to automatic. : : OLEDragOverd) ‘event is fired when the mouse is moved over an OLE container during OLE drag operation. i e OLESetDatal) event is fired when the target component issues a GetData method on the source's DataObject. The syntax for this event is as follows Private Sub Object_OLESetData (data As DataObject, dataformat As Integer) This event has two parameters. The data parameter contains a DataObject which will store the requested data. The dataformat parameter describes the format of the data stored in the data parameter. Example 8.8 The following example creates an OLE Drag and Drop Application. * Start a new project by selecting Standard EXE from the New Project dialog box. * Save the form as olefrm.frm and set the Name property to olefrm and caption property to OLE Drag and Drop Demonstration Project. + Add two text boxes of equal size as shown in Fig 8.4 below the project by dragging them from the toolbox. Name the text boxes as OLEtext1, and OLEtext2. Clear their text property and set their Multiline property to true. * Set the OLEDragMode to 1 — Automatic for OLEtextland OLEtext2. The following code is added in the OLEDragDrop() event of OLEtext1 Private Sub OLEText1 OLEDragDrop(Data As DataQbject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) OLEText1.Text = Data.GetData(vbCFText) End Sub ‘The following code is added in the OLEStartDrag() event of OLEtext1 Private Sub OLETextl OLEStartDrag(Data As DataObject, AllowedEffects As Long) Effect = vbDropEffectCopy Data.SetData OLETexti.Text, vbCFText End Sub Add the code in the OLEDragDrop() event of OLEtext2 Private Sub OLEText2 OLEDragDrop(Data As Data0bj EText2 ject, Effect As Long, B As Integer. Shift As Integer, X As Single, Y As Single) oe Effect = vbDropEffectCopy OLEText2.Text = Data.GetData(vbcFText) " End Subeee Objoot Linking and Embedding 349 FO to run the project. Let us typo in any loxt of our choice in the and drop it into OLEText2 and also vico-versa, ject as OLEDrag Drop,(see Fig. 8.4.) Grag and drop between applications, which support OLE drag and drop opera-
You might also like
Microsoft Access Language
PDF
No ratings yet
Microsoft Access Language
782 pages
VB 1st Unit
PDF
No ratings yet
VB 1st Unit
44 pages
Visual Basic6
PDF
No ratings yet
Visual Basic6
31 pages
Object Linking and Embedding: Citations Verification
PDF
No ratings yet
Object Linking and Embedding: Citations Verification
17 pages
Visual Basic 6.0
PDF
100% (1)
Visual Basic 6.0
164 pages
Object Oriented Programming With SQL
PDF
No ratings yet
Object Oriented Programming With SQL
6 pages
Unit 4
PDF
No ratings yet
Unit 4
14 pages
For A Good Program Design?: Visual Basic Basic of of
PDF
No ratings yet
For A Good Program Design?: Visual Basic Basic of of
11 pages
Unit 8
PDF
No ratings yet
Unit 8
8 pages
Using OLE Automation in Visual FoxPro
PDF
100% (2)
Using OLE Automation in Visual FoxPro
8 pages
VB Part 1
PDF
No ratings yet
VB Part 1
20 pages
VB 6
PDF
No ratings yet
VB 6
108 pages
Visual Basic
PDF
No ratings yet
Visual Basic
137 pages
Manual VB 6.0
PDF
No ratings yet
Manual VB 6.0
67 pages
Visual Programming - PDF
PDF
100% (1)
Visual Programming - PDF
143 pages
فيجول بيسك
PDF
No ratings yet
فيجول بيسك
60 pages
VB Day 7
PDF
No ratings yet
VB Day 7
11 pages
UNIT 4 FULL NOTES (1)
PDF
No ratings yet
UNIT 4 FULL NOTES (1)
13 pages
3 VB - Net Notes
PDF
No ratings yet
3 VB - Net Notes
29 pages
Learning Visual Basic & Oracle
PDF
No ratings yet
Learning Visual Basic & Oracle
772 pages
BT 12
PDF
No ratings yet
BT 12
25 pages
CCP603
PDF
No ratings yet
CCP603
21 pages
Unit 4 VB
PDF
No ratings yet
Unit 4 VB
67 pages
CCP603
PDF
No ratings yet
CCP603
20 pages
Object Linking Embedding
PDF
No ratings yet
Object Linking Embedding
2 pages
OLE Container Control
PDF
No ratings yet
OLE Container Control
1 page
Ole
PDF
No ratings yet
Ole
5 pages
IT 6th MAIN VB - Net Manual
PDF
No ratings yet
IT 6th MAIN VB - Net Manual
115 pages
VB Notes
PDF
No ratings yet
VB Notes
21 pages
3rd Year Paper - 1 Unit 4
PDF
No ratings yet
3rd Year Paper - 1 Unit 4
11 pages
Structure of A Visual Basic Application
PDF
No ratings yet
Structure of A Visual Basic Application
12 pages
Chapter 15-Advanced Topics in Visual Basic: 1. What Is An Activex Control? Give An Example
PDF
No ratings yet
Chapter 15-Advanced Topics in Visual Basic: 1. What Is An Activex Control? Give An Example
4 pages
Lesson 3 Working With Controls: 2.1: Programmer Talk
PDF
No ratings yet
Lesson 3 Working With Controls: 2.1: Programmer Talk
10 pages
Isual Basic 6.0 (VB6) Interview Question and Answer
PDF
No ratings yet
Isual Basic 6.0 (VB6) Interview Question and Answer
3 pages
Visual Basic IDE
PDF
No ratings yet
Visual Basic IDE
8 pages
Com Prog
PDF
No ratings yet
Com Prog
21 pages
VB1
PDF
No ratings yet
VB1
56 pages
Using Visual Basic's Standard Controls
PDF
No ratings yet
Using Visual Basic's Standard Controls
89 pages
Self - Learning Module - 2 - Q4
PDF
No ratings yet
Self - Learning Module - 2 - Q4
6 pages
Visual Basic Manual
PDF
No ratings yet
Visual Basic Manual
101 pages
Unit 3 - Introduction To Windows Controlss
PDF
No ratings yet
Unit 3 - Introduction To Windows Controlss
45 pages
Child Development and Pedagogy Ebook
PDF
No ratings yet
Child Development and Pedagogy Ebook
2 pages
Developing Application Rr2
PDF
No ratings yet
Developing Application Rr2
18 pages
Lecture 2-Intergrated Development Environment
PDF
No ratings yet
Lecture 2-Intergrated Development Environment
28 pages
Unit Ii Visual Basic Programming: Creating and Using Controls - Menus and Dialogs
PDF
No ratings yet
Unit Ii Visual Basic Programming: Creating and Using Controls - Menus and Dialogs
27 pages
OOPSVB
PDF
No ratings yet
OOPSVB
32 pages
VB.net
PDF
No ratings yet
VB.net
13 pages
Principal of Computer Science: Lec. Dr. Nuha H. Al-Hasan
PDF
No ratings yet
Principal of Computer Science: Lec. Dr. Nuha H. Al-Hasan
10 pages
AI
PDF
No ratings yet
AI
5 pages
Q41. What Is MDI? What Are The Advantages of MDI Forms and Its Features?
PDF
No ratings yet
Q41. What Is MDI? What Are The Advantages of MDI Forms and Its Features?
5 pages
Active Data Object in Visual Basic
PDF
No ratings yet
Active Data Object in Visual Basic
23 pages
II Year - DJA2E - Visual Basic
PDF
No ratings yet
II Year - DJA2E - Visual Basic
94 pages
II Year - DJA2E - Visual Basic
PDF
No ratings yet
II Year - DJA2E - Visual Basic
95 pages
VB-UNIT-1-Notes
PDF
No ratings yet
VB-UNIT-1-Notes
24 pages
Unit - 2 VB
PDF
No ratings yet
Unit - 2 VB
53 pages
M02 UML Overview
PDF
No ratings yet
M02 UML Overview
48 pages
Unit 1
PDF
No ratings yet
Unit 1
47 pages
Self - Learning Module - 1 - Q4
PDF
No ratings yet
Self - Learning Module - 1 - Q4
7 pages
Dialoagebox
PDF
No ratings yet
Dialoagebox
33 pages
Data Structures PPT 2020
PDF
No ratings yet
Data Structures PPT 2020
7 pages
Visual Basic Tutorial
PDF
No ratings yet
Visual Basic Tutorial
23 pages