Application of OLE Automation Technology in the Development of Delphi and MapInfo Integrated Map Abstract: This article discusses the use of OLE automation technology and visual programming tool Delphi to implement MapInfo map integration, and introduces the method of integrating maps and the message callback to MapInfo by way of routines. Thus realizing The ApplicaTIon Of OLE AutomaTIon Technology In Map-integraTIon Between Delphi And MapInfo TONG Gang, SHEN Qing-hua, BI Wei-zhun (College of AutomaTIon and Electronic, Qingdao University of Science and Technology, Qingdao 266042, China) Figure 1 The combination of Delphi and MapInfo Professional Fig.1 Combination of MapInfo Professional and Delphi To use callbacks, the client program must be able to act as an OLE automation server, and Delphi can be easily implemented. Figure 2 Schematic diagram of implementing MapInfo callback in Delphi
Shareconn can produce series waterproof cables, we often manufacture IP64 waterproof cables, IP67 waterproof cables and IP68 waterproof cables.
Shareconn provides expert solutions and an unlimited array of circular Connectors suited for various industrial applications in signal strength, data transmission, and power efficiency. We stand by the quality of our products and are confident we can increase our customer`s efficiency by reducing installation times and maintenance costs. Our circular connectors are available in various series; M5, M8, M10, M12, M16, M20, 7/8", M23, and RD24. They are widely used in industrial automation, machinery, LED, traffics, automated control systems, etc-
Waterproof Cable Assemblies ,Custom Cable Assembly,Waterproof Snowmobile Cable Assemblies ,Power Supplier Cable Assembly Shareconn Development CO.,LTD , http://www.share-conn.com
MapInfo is integrated into the Delphi application system to achieve the purpose of efficiently developing application-based GIS (geographic information system) software.
Keywords: geographic information system; OLE; MapInfo; Delphi; callback
Abstract: The method of realizing map-integration between Delphi and MapInfo using OLE automation technology is discussed, and the method of Map Integration and the Callbacks of MapInfo message is also introduced with example in this article. So MapInfo is integrated in application of Delphi to develop efficiently applied GIS (Geographical Information System).
Key words: GIS; OLE; MapInfo; Delphi; Callbacks
1 Introduction In the Windows system, there are two main methods of MapInfo secondary development, that is, use the development tools that come with it
MapBasic and use excellent development tools such as Delphi, VC, etc. Programs developed using MapBasic's own development tools must be run in the MapInfo environment, with large system resource overhead, low development efficiency, and weak functions
It is difficult to develop customized programs with friendly interface and powerful functions. He is more suitable for extending the functions of MapInfo. Use secondary development tools such as Delphi for secondary development. MapInfo support software is still used for background map processing. However, due to the use of professional development tools such as Delphi at the front desk, the development efficiency, development capabilities, localization, portability, etc. It is better than the tool that comes with it, and can continue to develop with the development of the entire software development industry [1]. The key to this method is the combination of the front-end custom program and the back-end MapInfo. At present, there are mainly developments using OLE Automation and MapX standard components.
Delphi is an object-oriented visualization software development tool of American INPRISE company, which has very powerful functions.
Can quickly and efficiently develop various programs based on the Windows environment, especially in the interface design, database programming and other aspects are unique. Object-oriented and visual design are its most prominent advantages. At the same time, it has powerful compilation capabilities, which greatly improves the efficiency of program execution and has become a development tool for many programmers.
2 OLE automation technology
OLE (Object Linking and Embedding) is a set of protocols and functions proposed by American Atduscorporation,
The purpose is to simplify the establishment and maintenance of compound files. It is the most complex subsystem in Microsoft Windows and a form of interprocess communication. The so-called object linking refers to a compound file that contains a reference pointer to refer to objects of other applications, and connects various Windows applications through OLE.
Using this OLE technology that enables users to share information resources of different applications, various applications can be easily integrated. OLE Automation is an interactive process communication mechanism designed for WINDOWS. It allows mutual access between different applications, allowing one application to access another application or DLL (dynamic link library), such as creating Excel in Delphi In the table, etc., and can access the methods and properties of these application objects (Method)
(Property), which overcomes the shortcomings of linking and nesting, that is, the object cannot be controlled by programming means, and the programmatic control of OLE components is realized. OLE automation includes two parts of applications: one is an application that exposes OLE components to make it controllable, called OLE automation server; the other is to use components provided by OLE server,
The application that controls the operation of this object is called an OLE client. Because the OLE automation server is very small, the stability, development and maintenance of the program are better than the traditional large programs. For the properties and methods of each OLE object, the programmer can decide to show certain properties and methods of the OLE automation server through OLE automation, while private objects are not visible to external users, but OLE client programmers only need to Knowing the name of the application that contains the object, the name of the object's class, and the names of the properties and methods you want to use, you can use the automation server [3]. Through the OLE automation technology, the Delphi language can be used for map integration. At this time, the Delphi program is the client program.
3 Using OLE automation technology to realize map integration For the integrated development of Delphi and MapInfo, Delphi can be used as the OLE automation controller or DDE
Customers, put MapInfo in the background, but it is best to use OLE automation, because this method is better than DDE
The method is faster and more reliable, and more error information can be obtained during the debugging operation. OLE automation is a technology for interoperability between Windows programs. You can create automation client programs to manipulate other programs, and MapInfo can be used as
OLE object server, and provides a set of corresponding methods.
3.1 Realize Delphi to obtain control and service to MapInfo Professional
Delphi program through a specific ActiveX control interface, execute the corresponding interface method function, MapInfo
Professional issues control commands and obtains its services to achieve the purpose of manipulating the MapInfo graphical data embedded in the Delphi program interface. For this technical point, you can use Delphi to start and control the functions supported by ActiveX (OLE)
MapInfo Professional runs. OLE automation is a technique for interoperating between Windows programs. Delphi fully supports OLE automation. You can create automation client programs to operate other programs. MapInfo can be used as a server for OLE objects and provides a corresponding set of methods. Delphi Create a customer automation program by creating an OLE object. To create an OLE object, you need to call the CreateOLE-Object function (defined in the comObj unit),
And the return result is assigned to a variable of type Variant, and then the program will access the OLE object through this variable.
The Delphi program at this time is an ActiveX (OLE) client application program that controls the operation of MapInfo Professional. MapInfo Professional running in the background is an ActiveX (OLE) automation server that provides services for Delphi programs.
The combination of Delphi and MapInfo Professional is shown in Figure 1.
3.2 Integration of Delphi application and MapInfo (1) Establish MapInfo automation object
Delphi creates a customer automation program by creating an OLE object. To create an OLE object, you need to call the CreateOLEObject function (defined in the OLEAUTO unit) and assign the return result to a variable of type Variant. The program will then pass this variable To access OLE objects. Set the variable name to Olemapinfo, the specific statement is as follows:
var OleMapInfo: Variant; // Declare OLE Variant type variable in Delphi application
Olemapinfo: = CreateOleobject ('mapinfo.application'); // Create OLE object
(2) Integrated MapInfo window in Delphi application
After the Ole automation object is created, the background MapInfo starts successfully. You can use the Do method of the object
Send commands, such as:
Olemapinfo.do ('set application window' + winhand);
Olemapinfo.do ('set next document parent' + winhand + 'style l'); // Relocate the MapInfo file window, which can also be used to relocate other special windows or legends, you can use the "setwindow" statement of MapBasic;
"Style1" can also be "style2" or "style3", which indicates the type of window created.
After completing the above settings, you can open the MapInfo file in the client program, such as:
Olemapinfo.do ('open table â€city.tabâ€');
Olemapinfo.do ('map from city'); // Open the MapInfo table and directly call the MapInfo menu or button command to operate the map window, just call MapInfo's
The RunMenuCommand method, which retains the function of the standard MapInfo button, greatly reduces the difficulty of reprogramming and easily implements the basic functions of MapInfo. The specific statement is as follows:
Olemapinfo.runmenucommand (1705); // zoom in
Olemapinfo.runmenucommand (1706); // zoom out
Olemapinfo.runmenucommand (1702); // roaming
(3) Terminate the MapInfo program When calling Delphi's CreateOleObject0 function to create a new MapInfo event, the MapInfo event is terminated when the object variable is released. When the object variable is a local variable, when exiting the local process When
The MapInfo event is released. If it is a global variable, it must be assigned the value "Unassigned" to be released. The statement is as follows: Olemapinfo: = Unassigned; // Release the global variable, terminate the MapInfo program Application.Terminate; // Terminate Delphi
3.3 Implementation of MapInfo CallBack in Delphi By setting the integrated map program, MapInfo can automatically send information to the client program. This type of flag information, that is, an event causes MapInfo to call the client program, is called a callback.
Its realization principle is shown in Figure 2:
Fig.2 The schematic diagram of realizing callback of MapInfo in Delphi
To implement CallBack of Maplnfo, there are generally the following steps:
1) Create a class and define several OLE methods (Method). If you want to get the content on the status bar of MapInfo,
Create the SetStatusText method (with a string parameter); if you want to get the ID number of the map window that has changed,
Then create the Windowcontentschanged method (with a shaping parameter);
2) Create an object for the class defined in 1);
3) After confirming that MapInfo has started, call MapInfo's SetCallBack method to register the OLE automation object in the "receiver" of the message sent by MapInfo;
4) Customize menus or buttons, and call the methods defined in 1) through these menus or buttons.
When an event occurs in MapInfo, MapInfo will organize the corresponding information into a certain form and pass it to the client application as a method parameter. Within these methods, programmers can process this information to extract the required information. Taking the status bar of a custom client program as an example, the callback is used as follows:
1) Build a class and define the SetStatusText method. This method takes a parameter StatusText of type WideString.
This parameter is passed by MapInfo to the client program.
Select File | New | ActiveX | Automation Object in Delphi6.0, start Automation
The Object wizard opens the "Type Library" editor to achieve. It is assumed here that the created class name is TmyCallBack.
2) Add a status bar to the application form.
3) Create an object using the class defined in the first step.
varCallBack: = TMyCallBack.Create;
4) Call the SetCallBack method of the automatic OLE object to pass parameters.
oleMapInfo.SetCallback (varCallBack As IMyCallBack);
5) Process the StatusText parameter passed by MapInfo in the SetStatusText method to control the display of the status bar.
procedure TMyCallBack.SetStatusText (const StatusText: WideString);
begin MainForm.StatusBar1.Panels [0] .Text: = StatusText;
// MainForm is the form that contains the map components, StatusBar1 is the default name for adding the status bar, panel, used to display the content on the status bar of MapInfo; End;
4 Conclusion Using Delphi to realize the secondary development of MapInfo through Delphi, Delphi fully utilized
The powerful database programming ability of the programming tool and the graphics processing ability of MapInfo Professional. And in the development process,
The two are independent of each other, Delphi can easily call MapBasic code without any changes, to achieve the functions and effects of MapInfo Professional through simple OLE automation technology to submit control commands, and achieve good application results. At the same time, in the processing method of MapInfo message callback, OLE automation technology can also be used to
MapInfo Professional's automatic callback message.