打印本文 打印本文 关闭窗口 关闭窗口
Building ActiveX Controls with Delphi 3
作者:武汉SEO闵涛  文章来源:敏韬网  点击数6453  更新时间:2009/4/23 18:31:11  文章录入:mintao  责任编辑:mintao
edientials and the file that contains the private key. In the Project|Web Deployment Options dialog, in the Project page, check the Code Sign Project checkbox. Then, turn to the Code Signing page and fill in the credentials file and private key file fields.

The application name and optional company URL fields will appear in the certificate dialog when the app is downloaded and verified. You should enter your company''''s information here.

Web Security

Security is an extremely important when you''''re building an ActiveX for web deployment. While ActiveX controls can be very powerful and convenient, they can also become your worst nightmare. As a builder of ActiveX controls, here are some things you should consider:

  • Be ethical. Don''''t build ActiveX controls that are harmful.
  • Build your control to be tamper-resistant.
  • Keep close watch on your software certificate. Establish notary procedures for its use. Keep records about what controls you''''ve signed and who signed it, and who had access to the signature key.
  • Don''''t give your control privileges over your network. Don''''t include default passwords, etc.
  • Set up your server so it knows who downloads the controls and when and where.

When deploying ActiveX controls in an Intranet, here''''s some advice:

  • Code signatures do not necessarily mean full security. Even signed, legitimate ActiveX controls have security flaws that can be taken advantage of.
  • Don''''t accept HTML pages containing an ActiveX control from anyone you don''''t trust as well as your least trustworthy staff. If you have a business partner that only publishes its data through an ActiveX, allow only that ActiveX to run, and only in the context of the page they published.
  • Caveat surfer

Data-aware controls

VB4 provides an open specification for "simple data bound controls." Such controls are typically controls that show a single value, like an edit field or a check box. Unlike the VB complex data binding spec, this standard has been adopted by a number of vendor, with the notable exception of Delphi itself. Despite the fact that Delphi doesn''''t host data-bound ActiveX controls, it can be used to produce them without too much trouble.

It doesn''''t take much to make a control data-aware, once you have a working ActiveX control. A simple data-aware ActiveX control has a special property that represents its "value". The property might be called Value, Text, Temperature, or whatever. This property is marked in the type library with several flags that indicate that it can be bound to. You can use the type library editor to set the flags in the control that indicate how the property is to be bound. Figure 3 shows how this can be done, by checking the Bindable, Request Edit, Display Bindable and Default Bindable flags of the property''''s Attributes pane.

The options tell the container that it can bind a data source value to this property. If the container chooses to bind a data source to the bindable property, the two always keep their values synchronized: when the data source changes value, the value property, and when the value property changes the data source changes value.

Figure 4. Type library editor, showing the Caption property defined as the default bound property.

The value property must also ask its container for permission to change the value property, before the property is actually changed. The container can refuse the modification if desired.

You can implement this relationship easily by taking advantage of the OnChanging and OnChanged events of your VCL control.

class TButtonXControl = ...;
  ...
private  
  FPropNotifySink: IPropNotifySink;
end;

procedure TButtonXControl.InitializeControl; 
begin
  FConnectionPoints.CreateConnectionPoint(IPropNotifySink, PropNotifySinkConnect); 
  FDelphiControl.OnChanged := OnChangedEvent;
  FDelphiControl.OnChanging := OnChangingEvent;
end;

procedure TButtonXControl.PropNotifySinkConnect(const Sink: IUnknown);
begin
  if Sink <> nil then 
    OleCheck(Sink.QueryInterface(IPropNotifySink, FPropNotifySink)) 
  else FPropNotifySink := nil;
end;

procedure TButtonXControl.Set_Caption(const Value: WideString);
begin
  FDelphiControl.Caption := TCaption(Value);
end;

procedure TButtonXControl.OnChangingEvent( Sender: TObject );
begin
  if FPropNotifySink <> nil then 
    if FPropertyNotifySink.RequestEdit( DISPID_CAPTION ) = S_FALSE then
      OleError( CTL_E_SETNOTPERMITTED );
end;

procedure TButtonX.OnChangedEvent( Sender:TObject );
begin 
  if FPropNotifySink <> nil then FPropNotifySink.OnChanged( DISPID_CAPTION );
end;

Conclusion

Delphi 3 provides you with an easy way to get started building ActiveX controls, bu combining a basic class framework called DAX with the VCL and a set of code-generation wizards. In this class, I''''ve explained how to convert a VCL control into an ActiveX control, and then how to add some of the more important ActiveX features to the control. I''''ve also explained how the Delphi ActiveX framework is built, and shown how you can extend it. This is an important skill, because ActiveX is an extremely fluid specification.

Further Reading

Microsoft''''s OLE web site is at http://www.microsoft.com/oledev. There''''s lots of really good stuff there.

Books

Designing and Using OLE Custom Controls, Tom Armstrong, M&T Press.

Tom maintains a web site at http://www.widgetware.com, including a comprehensive FAQ.

OLE Controls Inside Out, Adam Denning, Microsoft Press

Inside OLE, Kraig Brockschmidt, Microsoft Press

More book listings can be found at http://www.microsoft.com/oledev/books.htm

White papers

The Java Beans Specification, at http://splash.javasoft.com/beans/spec.html

This paper is a better explanation of component models than Microsoft''''s.

What OLE is Really About, by Kraig Brockschmidt, at http://www.microsoft.com/oledev/olecom/aboutole.htm. Best quote: "OLE is very much like the Coke bottle…"

Vijay Mukhi''''s site: http://www.neca.com/~vmis/ Vijay writes irreverently about various technologies, including ActiveX. Best quote: "Microsoft has won the battle for the Internet".

Documentation

OLE Controls specification, versions 1.0, 1.1 and 2.0, from Microsoft.

OC96 - additions to the OLE controls specification, from Microsoft.

ActiveX SDK Docs on ActiveX Controls: http://www.microsoft.com/msdn/sdk/platforms/doc/activex/src/olectrl.htm

Authenticode: see Microsoft''''s web site at http://www.microsoft.com/security/tech/misf8_2.htm

ActiveDesigner: see http://www.microsoft.com/intdev/sdk/dtctrl

Class hierarchies

Class hierarchies can be useful reference material when you can''''t find why something doesn''''t work. Look for cryptic comments like ''''some containers do this, so we have to bend over backwards here'''' to discover where a Microsoft developer has been there before you.

MFC - with Borland C++ 5.01 or Microsoft Visual C++ 4.2a.

ActiveX SDK - the BaseCtl framework. See http://www.microsoft.com/intdev/sdk/sdk.htm

ATL 2.x - with Microsoft Visual C++ 5.0

OLE Control Developer''''s Kit - from Microsoft, in the ActiveX SDK.

(C) Copyright 1997 by Conrad Herrmann. You may copy, modify, distribute or use for any purpose all ObjectPascal source code published in this article. All other rights reserved.

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 

打印本文 打印本文 关闭窗口 关闭窗口