转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
Building ActiveX Controls with Delphi 3         ★★★★

Building ActiveX Controls with Delphi 3

作者:闵涛 文章来源:闵涛的学习笔记 点击数:5170 更新时间:2009/4/23 18:31:11
operty doesn''''t exist, only that you won''''t be able to access it through a COM interface.

The Pascal Version of the Type Library

unit ButtonXControlLib;

{ This file represents the pascal declarations of a type library and will be written during each import or refresh of the type library editor. Changes to this file will be discarded during the refresh process. } { ButtonXControlLib Library } { Version 1.0 } interface uses Windows, ActiveX, Classes, Graphics, OleCtrls, StdVCL;
const LIBID_ButtonXControlLib: TGUID = ''''{B12863C0-A9EA-11D0-A6DF-444553540000}''''; const { TxDragMode } dmManual = 0; dmAutomatic = 1; { TxMouseButton } mbLeft = 0; mbRight = 1; mbMiddle = 2; const { Component class GUIDs } Class_ButtonX: TGUID = ''''{B12863C3-A9EA-11D0-A6DF-444553540000}''''; type { Forward declarations } IButtonX = interface; DButtonX_ = dispinterface; IButtonXEvents = dispinterface; ButtonX = IButtonX; TxDragMode = TOleEnum; TxMouseButton = TOleEnum; { Dispatch interface for ButtonX Control } IButtonX = interface(IDispatch) [''''{B12863C1-A9EA-11D0-A6DF-444553540000}'''']

This is the control''''s main (dual) automation interface. The controller object''''s class will implement all these methods.

procedure Click; safecall; 
function Get_Cancel: WordBool; safecall;
procedure  Set_Cancel(Value:WordBool); safecall;
function Get_Caption: WideString; safecall;
procedure Set_Caption(constValue: WideString); safecall;
function Get_Default: WordBool; safecall;
procedure Set_Default(Value: WordBool); safecall;
function Get_DragCursor: Smallint; safecall;
procedure Set_DragCursor(Value: Smallint); safecall;
function Get_DragMode: TxDragMode; safecall;
procedure Set_DragMode(Value: TxDragMode); safecall;
function Get_Enabled: WordBool; safecall;
procedure Set_Enabled(Value: WordBool); safecall;
function Get_Font: Font; safecall;
procedure Set_Font(const Value: Font); safecall;
function Get_ModalResult: Integer; safecall;
procedure Set_ModalResult(Value: Integer); safecall;
function Get_Visible: WordBool; safecall;
procedure Set_Visible(Value: WordBool); safecall;
function Get_Cursor: Smallint; safecall;
procedure Set_Cursor(Value: Smallint); safecall;
property Cancel: WordBool read Get_Cancel write Set_Cancel;
property  Caption: WideString read Get_Caption write Set_Caption; 
property Default: WordBool read Get_Default write Set_Default; 
property DragCursor: Smallint read Get_DragCursor write Set_DragCursor; 
property DragMode: TxDragMode read Get_DragMode write Set_DragMode; 
property Enabled: WordBool read Get_Enabled write Set_Enabled; 
property Font: Font read Get_Font write Set_Font;
property ModalResult: Integer read Get_ModalResult write Set_ModalResult;
property Visible: WordBool read Get_Visible write Set_Visible;
property Cursor: Smallint read Get_Cursor write Set_Cursor;
end;

{ DispInterface declaration for Dual Interface IButtonX }
DButtonX_ = dispinterface [''''{B12863C1-A9EA-11D0-A6DF-444553540000}'''']

This is the dispinterface version of the dual interface above.

procedure Click; dispid  1;
property Cancel: WordBool dispid 2; 
property Caption: WideString dispid 3; 
property Default: WordBool dispid 4; 
property DragCursor: Smallint dispid 5; 
property DragMode: TxDragMode dispid 6; 
property Enabled: WordBool dispid 7;
property Font: Font dispid  8; 
property ModalResult: Integer dispid 9; 
property Visible: WordBool dispid 10; 
property Cursor: Smallint dispid 11; 
end;
{ Events interface for ButtonX Control }
IButtonXEvents = dispinterface [''''{B12863C2-A9EA-11D0-A6DF-444553540000}'''']

This is the events dispinterface for the control. The control can fire these events to its container if the container installs an event sink.

 procedure OnClick; dispid 1; 
 procedure OnKeyPress(var Key: Smallint); dispid 2; 
end;

[Note: This file also includes declarations for TButtonX, which is the VCL class generated when you import the ButtonX control back into Delphi. For brevity''''s sake, I''''ve deleted this from this listing.]

implementation

end.

Advanced Features

The DAX class hierarchy provides mechanisms for you to implement or customize certain features of ActiveX controls. These features include per-property browsing, persistence streaming, verbs, property pages, ambient properties, and registration.

TActiveXControl defines an immense number of protected methods, most of which are simply implementations of its interface methods. Because they''''re just interface method implementations, you probably won''''t need to override any of them. Nevertheless, they are protected to allow for extending the hierarchy over time, especially as Microsoft defines new behaviors and changes existing ones.

This still leaves a few protected methods you might want to override in specific circumstances. The following sections describe these situations.

Per Property Browsing

Property browsing support allows a property inspector to display a property that doesn''''t normally have a text representation, such as a font. It also allows the inspector to show a dropdown list of values that the property can have. You only need to implement per property browsing where normal variant conversions can''''t convert your data to a string or won''''t do it in the way you want.

Per-property browsing is implemented using three methods that work together: GetPropertyString, GetProperty Strings, and GetPropertyValue.

function GetPropertyString(DispID: Integer; var S: string): Boolean;
When the property inspector displays a property, it calls this method to see if the property has a display string. If you want your property to have a display string, add a case statement for the property, calculate the string you want to show for the property''''s current value, and return True. Otherwise, return False;

Example: The following code demonstrates how you can show the Cursor property as a string surrounded by square brackets.

function TButtonX.GetPropertyString( id: Integer; var S: String): Boolean;
begin
  case id of
  10: {Caption} 
    begin 
      S := ''''['''' + IntToStr( Get_Cursor ) +'''']''''; 
      Result := True; 
    end; 
  else 
    Result := False;
  end;
end;

Bug: There was a bug in the shipping version of Delphi 3.0, which may be fixed by the time you read this. The implementation of TActiveXControl.GetDisplayString was left blank, when it should actually pass control to the GetPropertyString method mentioned above. Fortunately, this is easy to work around, since it simply requires supplying an implementation for IPerPropertyBrowsing.GetDisplayString. The following code shows the two places to modify the code to reimplement GetDisplayString correctly, in the class definition and in the class implementation.

TButtonX = class(TActiveXControl, IButtonX, IPerPropertyBrowsing) 
  ... 
  function GetDisplayString(dispid: TDispID; out bstr: WideString):HResult; stdcall;
  ...
  end;
  ...
function TButtonX.GetDisplayString(dispid: TDispID; out bstr: WideString): HResult;var S: String; 
begin 
  if GetPropertyString( dispid, S ) then
  begin 
      bstr := S; 
      Result := S_OK; 
  end 
  else
    Result := E_NOTIMPL;
end;

function GetPropertyStrings(DispID: Integer; Strings: TStrings): Boolean; 
GetPropertyStrings and GetPropertyValue work in tandem. GetPropertyStrings is called to populate a string list with a list of values that will be shown in a dropdown listbox. Once the user selects one of these, GetPropertyValues is called to retrieve the variant value for the selected property.
procedure GetPropertyStrings(DispID: Integer; Strings: Tstrings): Boolean;
begin
  if  DispID = DISPID_FOO then
  begin
    Strings.Add(''''Ten''''); 
    Strings.Add(''''Twenty''''); 
    Strings.Add(''''Thirty'''');
    Result := True;
  end
  else
    Result := False;
end;

procedure GetPropertyValue(DispID, Cookie: Integer; var Value: OleVariant); 
begin 
  if dispid = DISPID_FOO then 
     Value := Cookie *10; 
end;

Custom Object Streaming

The default streaming behavior for DAX objects is to read or write all the property values from the VCL control using the VCL format. You can add extra information to the persistence stream by overriding the LoadFromStream or SaveToStream methods. Be sure to call the inherited method in order to load or save the control''''s properties properly.

These methods are defined as:

procedure
LoadFromStream(const
Stream: IStream); procedure
SaveToStream(const
Stream: IStream);

They read

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


[办公软件]excel中的VBA中的With语句的使用介绍及实例  [系统软件]OLE with the internet explorer
[Delphi程序]Delphi深度探索-数据库明了的ActiveX控件  [Delphi程序]override deal with window closing in database …
[Delphi程序]DELPHI实现activex控件的限制  [Delphi程序]Delphi使用VB编写的ActiveX控件全攻略
[Delphi程序]Delphi使用VB6编写的ActiveX控件???  [Delphi程序]MediaPlayer9 ActiveX 攻略(原创)
[VB.NET程序]Socket Programming with VB  [VB.NET程序]Managing Windows with WMI
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台