Sunteți pe pagina 1din 18

ODBC Classes

These classes work with the other application framework classes to give easy access to a wide variety of databases for which Open Database Connectivity (ODBC) drivers are available.

Programs that use ODBC databases will have at least a CDatabase object and a CRecordset object. CDatabase Encapsulates a connection to a data source, through which you can operate on the data source. CRecordset Encapsulates a set of records selected from a data source. Recordsets enable scrolling from record to record, updating records (adding, editing, and deleting records), qualifying the selection with a filter, sorting the selection, and parameterizing the selection with information obtained or calculated at run time. CRecordView Provides a form view directly connected to a recordset object. The dialog data exchange (DDX) mechanism exchanges data between the recordset and the controls of the record view. Like all form views, a record view is based on a dialog template resource. Record views also support moving from record to record in the recordset, updating records, and closing the associated recordset when the record view closes. CDBException An exception resulting from failures in data access processing. This class serves the same purpose as other exception classes in the exception-handling mechanism of the class library. CFieldExchange Supplies context information to support record field exchange (RFX), which exchanges data between the field data members and parameter data members of a recordset object and the corresponding table columns on the data source. Analogous to class CDataExchange, which is used similarly for dialog data exchange (DDX).

ActiveX

ActiveX is an open integration platform that provides developers, users, and Web producers a fast and easy way to create integrated programs and content for the Internet and Intranets. Using ActiveX, you can easily insert multimedia effects, interactive objects, and sophisticated programs into a Web page, creating a user experience comparable to that of high quality multimedia CD-ROM titles. ActiveX is a standard that enables software components to interact with one another in a networked environment, regardless of the language(s) used to create them. Most World Wide Web (WWW) users will experience ActiveX technology in the form of ActiveX controls, ActiveX documents, and ActiveX scripts.

ActiveX Controls
ActiveX controls, formerly known as OLE controls or OCX controls, are components (or objects) that you can insert into a Web page or other program so that you can reuse packaged functionality that someone else programmed. For example, the ActiveX controls that are included with Internet Explorer enable you to enhance your Web pages with sophisticated formatting features and animation. A key advantage of ActiveX controls over Java programs and Netscape plug-ins is that ActiveX controls can also be used in programs written in many programming languages, including all of the Microsoft programming and database languages.

Creating an ActiveX Control


Simply follow these steps in order to create an ActiveX control. A)Using the AppWizard to create an ActiveX Control project 1. Select New from File menu 2. Click the Projects tab and select the type of project as MFC ActiveX Control Wizard from the list. 3. Name of new project Plot and then click the OK button. 4. Take all the defaults values of the next dialog (titled MFC ActiveX Control Wizard - Step 1 of 2) and click the Next button 5. From the next dialog (titled MFC ActiveX Control Wizard - Step 2 of 2), locate the combo box with the prompt Which window class, if any, should this control subclass?. Drop down the list and select the entry STATIC from that list. We're using a static control in this example since we'll just be displaying data (and not accepting input). 6. Click on Advanced button and check the Flicker free activation checkbox. 7. Now click the Finish button. At this point, the AppWizard will generate the following three classes on your behalf. B) Adding "Stock" properties The term stock properties means that its one of a set of common properties that MFC code stores and initializes for you. The MFC code also performs appropriate action when the value of a stock property is changed. The ClassWizard provides code for changing nine (9) such properties. Since these properties are built-in, they are

obviously the easiest to deal with in terms of the work required by the developer. As you'll see shortly, you literally don't add a single line of code to add stock property to your control! The ClassWizard provides code for the following stock properties:

Appearance BackColor ForeColor BorderStyle Font Caption Enable Text hWnd

From these, we will work with the Appearance, BackColor, ForeColor and BorderStyle properties. C) Adding Custom Properties
Custom properties are properties you devise yourself for your control. For the plot control I have added only four custom properties "Grid On/Off" and "X-Log". The grid properties will control the visibility of the control grid. The "x-log" property will be used to plot the horizontal axis in the logarithmic scale.

DLL
Dynamic-link library (also written without the hyphen), or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems. These libraries usually have the file extension DLL, OCX (for libraries containing ActiveX controls), or DRV (for legacy system drivers). The file formats for DLLs are the same as for Windows EXE files that is, Portable Executable (PE) for 32-bit and 64-bit Windows, and New Executable (NE) for 16-bit Windows. As with EXEs, DLLs can contain code, data, and resources, in any combination. In the broader sense of the term, any data file with the same file format can be called a resource DLL. Examples of such DLLs include icon libraries, sometimes having the extension ICL, and font files, having the extensions FON and FOT. Features: Since DLLs are essentially the same as EXEs, the choice of which to produce as part of the linking process is for clarity, since it is possible to export functions and data from either. It is not possible to directly execute a DLL, since it requires an EXE for the operating system to load it through an entry point, hence the existence of utilities of rundll which provide the entry point and minimal framework for DLLs that contain enough functionality to execute without much support. DLLs provide a mechanism for shared code and data, allowing a developer of shared code/data to upgrade functionality without requiring applications to be re-linked or re-compiled. From the application development point of view Windows and OS/2 can be thought of as a collection of DLLs that are upgraded, allowing applications for one version of the OS to work in a later one, provided that the OS vendor has ensured that the interfaces and functionality are compatible. DLLs execute in the memory space of the calling process and with the same access permissions which means there is little overhead in their use but also that there is no protection for the calling EXE if the DLL has any sort of bug. Dynamic linking has the following advantages: Saves memory and reduces swapping. Many processes can use a single DLL simultaneously, sharing a single copy of the DLL in memory. In contrast, Windows must load a copy of the library code into memory for each application that is built with a static link library. Saves disk space. Many applications can share a single copy of the DLL on disk. In contrast, each application built with a static link library has the library code linked into its executable image as a separate copy. Upgrades to the DLL are easier. When the functions in a DLL change, the applications that use them do not need to be recompiled or relinked as long as the function arguments and return values do not change. In contrast, statically linked object code requires that the application be relinked when the functions change. Provides after-market support. For example, a display driver DLL can be modified to support a display that was not available when the application was shipped. Supports multilanguage programs. Programs written in different programming languages can call the same DLL function as long as the programs follow the function's calling convention. The programs and the DLL function must be compatible in the following ways: the order in which the function expects its arguments to be pushed onto the stack, whether the function or the application is responsible for cleaning up the stack, and whether any arguments are passed in registers. Provides a mechanism to extend the MFC library classes. You can derive classes from the existing MFC classes and place them in an MFC extension DLL for use by MFC applications.

Eases the creation of international versions. By placing resources in a DLL, it is much easier to create international versions of an application. You can place the strings for each language version of your application in a separate resource DLL and have the different language versions load the appropriate resources. A potential disadvantage to using DLLs is that the application is not self-contained; it depends on the existence of a separate DLL module.

Diff Between ActivxEXE and ActivexDLL Activex DLL It runs within the main program address space. So calling method is fast. It is easy to test. Activex EXE This runs in a in a separate process. this is useful for creating components that can run as stand-alone, that is they can be run by clicking on the icon. This is similar to Excel: you can click on the Excel icon and launch Excel or you can create an Excel object from VB.
Dlls are in-process components. They run in the same memory as the calling application and hance are faster. Dlls are preferred if they exist on the same machine. Exes are out-process components. They run in a separate memory location.When a method/function is called from an exe, the parameters and also the result of the method/function have to cross the network boundries through marshalling and hence are slower.For remote access Exes are the choice. active dll is fast active exe is slow ActivexDLL is executes in in process ActivexExe executes in outprocess

Windows Form Properties

Event
An event procedure is an independent group of commands that is executed whenever an event occurs during program execution. Typically, an event occurs when the user takes some action, such as clicking on a control icon, or dragging an icon to another location. Many (though not all) Visual Basic controls have event procedures

associated with them. Each event procedure begins with a Sub statement, such as Private Sub Command1_Click(), and ends with an End Sub statement. Between the Sub and End Sub statements is a group of instructions, such as those discussed in the last two chapters, that are executed when the user initiates the corresponding event. The parentheses in the Sub statement may contain arguments special variables that are used to transfer information between the event procedure and the calling routine (see Chap. 7 for more information on this topic). Command buttons are often used to execute Visual Basic event procedures. Thus, when the user clicks on a command button during program execution, the statements within the corresponding event procedure are carried out. The statements within the event procedure may involve the properties of controls other than the command button. For example, a command-button event procedure may result in new values being assigned to the properties of a label or a text box. A typical event procedure is shown below: Private Sub Command1_Click() Label1.Caption = "Hello, " & Text1.Text & "! Welcome to Visual Basic." Label1.BorderStyle = 1 Label1.Visible = True End Sub From the first line (i.e., the Sub statement), we see that this event procedure is associated with command button Command1, and it is a response to a click-type event. The three assignment statements within the event procedure will be executed whenever the user clicks the mouse on command button Command1 during program execution. ODBC vs OLE DB ODBC is Open Data Base Connectivity, which is a connection method to data sources and other things. It requires that you set up a data source, or what's called a DSN using an SQL driver or other driver if connecting to other database types. Most database systems support ODBC. OLE is Object Linking and Embedding. OLEDB is partly distinguished from OLE itself, now called "automation". OLEDB is the successor to ODBC, a set of software components that allow a "front end" such as GUI based on VB, C++, Access or whatever to connect with a back end such as SQL Server, Oracle, DB2, mySQL etal. In many cases the OLEDB components offer much better performance than the older ODBC. OLEDB is a different type of data provider that came about with MS's Universal Data Access in 1996 and does not require that you set up a DSN. It is commonly used when building VB apps and is closely tied to ADO. It works with COM, and DCOM as of SQL 7.0.

Procedures

S-ar putea să vă placă și