用delphi製作OCX庫文件(三)

開發步驟:
1、創建ActiveX Library工程。
2、創建COM Object。
3、創建Type Library,並創建相應接口。
4、創建接口對應的函數和實現。

具體如下:
3、創建Type Library,並創建相應接口。
view|type library

找到已經生成的type library,其實和TLB文件是對應的。
我們可以看到上一步生成的對象也含在裏面。


我們在裏面生成新的方法,並定義好方法的參數。


注意:integer和String在OCX裏對應的類型分別爲long和BStr或者WideString。目的是爲了便於網絡上傳播時各個系統兼容的需要。
返回值必須爲指針類型,Modifier爲返回標誌,[in]爲輸入參數,[out,RetVal]爲輸出加返回值。

在Class Name(本例裏類名裏填Object,可按自己需要填寫) 填寫類名.(Instancing:實例創建方式,Threading Model:線程模式.) 其

中Implemented Interface(接口名)自動生成.

點刷新按鈕之後,在TLB和實現單元裏都有了關於這個接口函數的定義。


剩下的只要在實現單元裏完成實現的代碼即可。

4、創建接口對應的函數和實現。
具體實現。

type
  TOjbect = class(TTypedComObject, IOjbect)
  protected
    function Method1(Param1, Param2: Integer; out Param3: Integer): HResult;
      stdcall;
  end;

 

implementation

uses ComServ;

 

function TOjbect.Method1(Param1, Param2: Integer;
  out Param3: Integer): HResult;
begin
  //具體實現
end;

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章