Active form displays the title bar and page Jump

Source: Internet
Author: User
Tags reflector

I have rarely written active form before. After all, it is really troublesome to install.

No way. A friend asked him how to hide the active form on the page. It is said that he spent money and the man was still confused. Because several circuit boards are not completed on the hand, they have been soldered.

After compiling the program, you will find that you can use the External Object tag to set the attributes of the object, height, and width. If both devices are 0, they will naturally be hidden, when creating a form, you can use the mode form to display the form with a label bar.

As for webpage jump, he used ShellExecute before. This function will jump out of a new window. In fact, you can use the following method.

Procedure tactiveformdx. button1click (Sender: tobject );
Begin
Hlinknavigatestring (iunknown (vclcomobject), 'HTTP: // Mn/activeformd/wolf.htm ');
End;

Procedure tactiveformdx. button2click (Sender: tobject );
Begin
Hlinkgoback (iunknown (vclcomobject ));
End;

The following is a detailed description of the function:

When publishing an application that uses ActiveX controls, the ocx file or DLL file of the ActiveX control should be attached, and before running the application, you must first register the ActiveX control in the system registry. Note: Some ActiveX controls use other DLL files. These files are also required. You can use regsvr32.exe to register ActiveX controls, which can be found in windows. You can also use tregsvr.exe In the BIND directory in the delphidevelopment environment directory to register the service. Another example is to integrate the registration code of the activexcontroller into the application. delphihas downloaded the source code of tregsvr.exe and demonstrated how to register the ActiveX control.

ActiveX Control wizard)
This wizard allows you to convert a VCL control into an ActiveX control. The VCL control that can be converted into an ActiveX control must meet the following three principles:
The. VCL control must be in the currently installed design package (it must be in the component panel ).
The. VCL control must be a derived class of twincontrol. The current non-window control cannot be converted to an ActiveX control.
The. VCL control must have not been listed by the registernonactivex () process.
Many standard VCL controls cannot be converted to ActiveX controls because some of them are meaningless or
It requires a lot of work and exceeds the functions provided by the wizard.
Note: although the ActiveX Wizard cannot convert a non-window control to an ActiveX control, it can use the Delphi ActiveX (Dax) framework.
To manually write such controls.

ActiveX control options ):
. Make control licensed, select this option, a license file (LIC) will be generated, this is to make other developers in different
This ActiveX control can be used in the development environment.
In order to use this control, in addition to the ocx file of the ActiveX control, the license file is also required. Dax requires a license file and ActiveX
The ocx file of the control is released to the user's machine. The license string is a parameter of the ActiveX control factory constructor. In the wizard
Select make control licensed. This option will generate a guid string and insert this string to the calls of the class factory constructor.
And the LIC file. If this ActiveX control is used in development tools, Dax will compare the license string of the class factory
Can be compared by string. If matched, the control instance can be created. When compiling an application that uses this ActiveX control,
The license string is embedded in the application, but the LIC file is no longer required to run the application.
. Include version information, select this option, a versioninfo resource will be connected to the ocx file, in its string
There is a variable named oleselfregister in the file information. Its value is 1, which is used to be compatible with the host of the old ActiveX control,
For example, in Visual Basic 4.0, You can edit this variable on the versioninfo page of the Project Options dialog box.
. Include about box. Select this option to connect the "about" dialog box to the ActiveX control.
In order to activate this dialog box, right-click the ActiveX control and right-click it. This about dialog box is a common Delphi Form.

The following describes how to convert a VCL control to an ActiveX control in the ActiveX control Wizard:
1) The Wizard determines which unit contains the selected VCL control. After being processed by the compiler, the compiler generates special symbol information corresponding to the attributes, methods, and events of the VCL control.
2) create a Type Library for this project, including an interface with properties and methods, an event scheduling interface, and a control class that represents ActiveX controls.
3) The Wizard traverses all the symbol information of the VCL control, adds the attributes and methods to the interface, and adds the events to the scheduling interface.
Note: Only those attributes, method parameters, return values, and event types that are compatible with automation can be added to the Type Library.
Data types include byte, samllint, integer, single, double, currency, tdatatime, widestring,
Wordbool, psafearray, tdecimal, olevariant, iunknown, and idispatch. However, this rule also has exceptions.
The data types are tstrings, tpicture, and tfont. For these types, the wizard encapsulates them
Compatible type. The three types correspond to the following automatic interfaces: istrings, ipicture, and ifont.
4) once all the attributes, methods, and events are added to the Type Library, the Type Library editor generates an Object Pascal translation containing the content of the Type Library.
5) The Wizard generates an ActiveX control implementation file, which contains a tactivexcontrol object that implements the interface described in the Type Library, and automatically implement the attributes, methods, and events in the original VCL.
Note: There is a class similar to tmemox in the unit file of the Type Library, which is inherited from tolecontrol, so that you can
Add the xxx_tlb unit to the widget panel as long as the ActiveX control is added to the design period package.

Delphi ActiveX framework (Dax) is in the axctrls unit. An ActiveX control can be regarded as an automation object because it needs to implement the idispatch interface and other interfaces. Tactivexcontrol is the derived class of tautoobject. It can implement the interface required by an ActiveX control. The Dax framework is a two-way framework. The tactivexcontrol part of ActiveX can communicate with twincontrol In The VCL control. Just like all COM objects, ActiveX controls are created by class factories. tactivexcontrolfactory in Dax is the class factory of tactivexcontrol objects. The class factory instance is created in the initialization part of the control implementation unit. The class constructor declaration is as follows:
Constructor tacitvexcontrolfactory. Create (comserver: tcomserverobject; activexcontrolclass:
Tactivexcontrolclass; wincontrolclass: twincontrolclass; const classid: tguid; toolboxbitmapid:
Integer; const licstr: string; miscstatus: integer; threadingmodel: tthreadingmodel = tmsingle );
Comserver is used to specify a tcomserver instance, which is usually the global variable comserver in the comserv unit.
Activexcontrolclass is used to specify the name of the derived class of tactivexcontrol, which is defined in the implementation file.
Wincontrolclass specifies the name of The VCL twincontrol derived class. ActiveX control is converted from it.
Classid specifies the Class Identifier (CLSID) of the ActiveX control, which is listed in the Type Library editor.
Toolboxbitmapid specifies the resource identifier of a bitmap. This bitmap serves as an ActiveX control icon in the widget panel.
Licstr is used to specify the license string of the ativex control. If this string is set to null, it indicates no permission.
Miscstatus is used to specify the olemisc_xxx status flag of the ActiveX control. These labels determine how an ActiveX control draws in a window.
Output, whether other controls can be included. For more information about the meanings of these labels, see olemisc topics in Microsoft develpoer's network.
Threadingmodel is used to specify the thread mode of ActiveX controls. Note that this parameter is only used to specify a line for ActiveX controls.
But it cannot guarantee that the ActiveX control can work safely in this thread mode. It only determines how the ActiveX control is registered.
Thread security needs to be programmed by the programmer.

One of the values of the olemisc_xxx parameter is olemisc_simpleframe. When the controlstyle attribute of the VCL control contains
Csacceptscontrols is automatically added to the ActiveX control. This means that ActiveX control can become another ActiveX control.
Container. In the tactivexcontrol class, there is a message processing structure that enables the control to work correctly to process messages of subcontrols. Normally
Values are automatically set in the Wizard. If you do not want this, you should manually remove this sign in the code that calls the class factory constructor.

Some ActiveX controls must have messages to work correctly. Therefore, Dax will create a reflector window, whose task is to receive messages and put it
Are passed to the VCL control. Any VCL control that requires a reflector window has a csreflector flag in the controlstryle attribute. If one
The custom twincontrol control that processes notification messages must have this flag value in the controlstyle set of the control constructor.

VCL provides a simple method to determine whether a control is currently in the design or runtime, as long as it is checked in the componentstate attribute
Whether the csdesigning flag exists. Although ActiveX controls can also be used for similar judgment, it is not easy to implement, and it needs to obtain
Pointer of the iambientdispatch scheduling interface of the container and check the usermode attribute of the scheduling interface. You can use the following code:
Function iscontrolrunning (Control: iunknown): Boolean;
VaR
Oleobj: ioleobject;
Site: ioleclientsite;
Begin
Result: = true;
// Obtain the ioleobject pointer of the control, obtain the ioleclientsite of the container, and then obtain the iambientdispatch.
If (control. QueryInterface (ioleobject, oleobj) = s_ OK) and
(Oleobj. getclientsite (SITE) = s_ OK) and (site <> nil) then
Result: = (site as iambientdispatch). usermode;
End;

The LIC file is not the only license policy. For example, some developers think it is troublesome to append a file, and they prefer to register a file in the registry.
A license string. Dax uses a simple method to achieve this goal. In tactivexcontrolfactory, there is a method called
Hasmachinelicense. By default, this method searches for the license string in the LIC file, but you can make this method in the Registry
Search for the license string. For example, the following code shows how a derived class of tactivexcontrolfactory can search for license words in the registry.
String.
Type
Treglicactivexcontrolfactory = Class (tactivexcontrolfactory)
Protected
Function hasmachinelicense: Boolean; override;
End;

Function treglicactivexcontrolfactory. hasmachinelicense: Boolean;
VaR REG: Tregistry;
Begin
Result: = true;
If not supportslicensing then exit;
Reg: = Tregistry. Create;
Try
Reg. rootkey: = hkey_classes_root;
Result: = reg. openkey ('\ licenses \' + licstring, false );
Finally
Reg. Free;
End;
End;
Add the license string to the reg file of the Registry file:
Regedit4

[Hkey_classes_root \ licenses \ {C06EFEA0-06B2-11D1-A9BF-B18A9F703311}]
@ = "Licensing info for DDG demo ActiveX control"

The properties page provides a dialog box to modify the properties of ActiveX controls. In the control container, right-click the control and
Select a command from the menu to open a property page of the control.
1. Standard property page
Dax provides standard property pages for istring, ipicture, tcolor, and ifont. The clsid of these property pages is defined in axctrls.
Unit. They are declared as follows:
Const
Class_dcolorproppage: tguid = '{5cff5d59-5946-11d0-bdef-00a024d1875c }';
Class_dfontproppage: tguid = '{5cff5d5b-5946-11d0-bdef-00a024d1875c }';
Class_dpictureproppage: tguid = '{5cff5d5a-5946-11d0-bdef-00a024d1875c }';
Class_dstringproppage: tguid = '{F42D677E-754B-11D0-BDFB-00A024D1875C }';
When using any of the preceding property pages in ActiveX controls, you only need to pass their clsid to the definepropertypages () side of the control.
The definepropertypage parameter in method. Example:
Procedure tmemox. definepropertypages (definepropertypage: tdefinepropertypage );
Begin
Definepropertypage (class_dcolorproppage );
Definepropertypage (class_dfontproppage );
Definepropertypage (class_dstringproppage );
End;
2. Custom property page
Example: Create an ActiveX control and a property page. design the interface and Code on the property page,
Rename the default type identifier class_propertypage1 on the property page to another name you like.
Add the following code to the definepropertypages method:
Procedure tmemox. definepropertypages (definepropertypage: tdefinepropertypage );
Begin
Definepropertypage (class_dstringproppage); // This is the CLSID of the standard property page.
Definepropertypage (class_propertypage1 );
End;
When implementing custom property pages, oleobject is used to interact with ActiveX controls in the property pages. Oleobject is a variant that can reference
ActiveX Control's idispatch interface. The updatepropertypage () method and updateobject () method of the property page are generated by the wizard.
When the property page is activated, updatepropertypage () is called to display the property value of the ActiveX control on the property page. When
When you click the OK or Apply button on the property page, the updateobject () method is called. In this way, you will have the opportunity to change
Properties of the new ActiveX control. When a button on the property page is pressed, the modified () method of the property page should be called to make the Apply button valid,
And temporarily update the properties of the ActiveX control.

Activeform:
In terms of functions, activeform is very similar to ActiveX controls,
The interfaces of activeform in the Type Library are flat, rather than nested as VCL. This indicates that if an activeform has
You cannot access the buttons on activeform in a way similar to activeform. Button. buttonproperty.
Is the client program that uses the activeform ). The simplest way to solve this problem is to convert the button attribute to activeform.
Attribute. You only need to take two steps. Here we assume the caption attribute of the button to be converted:
1) Add a public new attribute called buttoncaption in the activeform Declaration of the implementation file. It has read and write methods to read
Write button caption attribute.
2) Add a new attribute named buttoncaption to the activeform interface in the Type Library. Delphi will automatically generate this attribute
Program Framework for reading and writing methods. You must write your own code to improve the program by reading and writing the buttoncaption attribute of activeform.
Activeform is ideal for transmitting small programs on www. The web page function and
Appearance. Because ActiveX controls can run on Web browsers, it makes sense to call functions and interfaces of Web browsers. Web
Most of the browser functions and interfaces are in the urlmon unit. The simplest of them is the hlinkxxx () function, which allows the browser to jump to different
Location. For example, the hlinkgoforward () and hlinkgoback () functions allow the browser to jump back and forth in the history.
The hlinknavigatestring () function enables the browser to jump to a specific URL. These functions are declared in the urlmon unit as follows:
Function hlinkgoforward (punk: iunknown): hresult; stdcall;
Function hlinkgoback (punk: iunknown): hresult; stdcall;
Function hlinknavigatestring (punk: iunknown; sztarget: pwidechar): hresult; stdcall;
The punk parameter is the iunknown interface of the ActiveX control. For the ActiveX control, the control as iunknown can be passed to this parameter.
For activeform, you can pass iunknown (vclcomobject) to this parameter. Hlinknavigatestring ()
The sztarget parameter is used to specify a URL. You can call the urldownloadtofile () function to download an object from the server.
The urlmon statement is as follows:
Function urldownloadtofile (P1: iunknown; P2: pchar; P3: pchar; P4: DWORD; P5:
Ibindstatuscallback): hresult; stdcall;
P1 represents the iunknown interface of the ActiveX control, which is similar to the punk parameter of the hlinkxxx () function. The P2 parameter is the URL of the file to be downloaded.
The P3 parameter is used to specify the path and name for downloading the object to the local device. The P4 parameter must be set to 0. The P5 parameter is used to specify an optional
Ibindstatuscallback interface pointer. This interface is used to obtain the additional information of an object during download.
Delphi IDE can easily publish ActiveX controls on the web site. To achieve this function, you must Edit ActiveX controls.
Select project> Web deployment options. The options in this dialog box are described as follows:
1. Project page
The target dir box is used to specify the target path of the ActiveX control to be released. Suppose we can map a drive to a Web server-
In the target dir box, you must enter a regular or UNC path name, with no file name.
The target URL box is used to enter the URL of the path specified by the target dir box. A valid URL must be http: //, file ://,
FTP: // is the prefix. Do not enter a file name in this box.
The HTML dir box is used to specify a path for saving the HTML document generated during the trial. It is usually the same as the path specified in the target dir box.
Use cab File compression. If this option is selected, the ocx file will be compressed in Microsoft Cabinet (CAB) format. In
We recommend that you select this option for low-bandwidth networks.
Include File version number. This option determines whether the HTML file or inf file must contain the version number. We recommend that you select this
To prevent users from downloading the downloaded controls.
Autoincrement release number. If this option is selected, the release number in version information is automatically increased.
Code Sign project. If there is a digital signature authorization certificate, the IDE can automatically add a digital signature to the ActiveX project.
Deploy required packages. If the ActiveX project uses a package, the required package is automatically included when the ActiveX project is released.
Deploy additional files. If you want to publish files with other files, select this check box.
2. Packages page and additional files page
If the use cab File compression check box is selected on the project page
In the cab options box, you can select whether to compress the cab file with OCX or separately. Generally, the files are compressed to their respective
In the cab. This prevents users from downloading all files every time. If the use file versioninfo check box is selected, the publishing engine determines
Determines whether the selected file has version information. If yes, the version number in versioninfo will be added to the INF file. Target URL box default
The content in the target URL box on the project page, that is, the URL where the file can be downloaded. If the ActiveX control user has installed
Files, leave this box empty. The target directory editing box specifies the path to which the file is copied to the server. If the file
If it is already on the server, leave the edit box blank to avoid duplicate replication.
3. Code signing page
The code signing page can be used to specify the authorization file and private key file. You can also specify the ActiveX Control name, company URL,
Compression Algorithm type, whether to stamp the authorization file with a timestamp. It is recommended to stamp the time stamp so that the signature will still be valid even if the authorization file expires.
Note: If the settings on the project page are incorrect, when the control appears on the web page, there is a red X in the upper left corner of the control. Output
In this case, the most common error is that the control URL is incorrect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.