电竞比分网-中国电竞赛事及体育赛事平台

分享

COM深入編程學(xué)習(xí)筆記6

 aaie_ 2012-10-16
                             VC                    Delphi
基本類型: boolean           unsigned char         boolean
           Byte              unsigned char         byte
           small             char                  char
           short             short                 word
           long              long                  long
           hyper             _int64                _int64
           float             float                 float
           double            double                double
           char              char                  char
           wchar_t           wchar_t               integer
           enum              enum                  enum
           接口指針          接口指針              接口指針
 
擴(kuò)展類型:
           Variant           Variant               Variant/OleVariant
           BSTR              BSTR                  WideString
           Variant_BOOL      Short[1/0]            boolean[TRUE/FALSE]

1. 創(chuàng)建ActiveX控件
  
   這個比較簡單,和創(chuàng)建COM Object差不多,需要選擇ActiveX Control,
   派生TCheckListBoxX = class(TActiveXControl, ICheckListBoxX);
   Delphi可以快速把標(biāo)準(zhǔn)VCL轉(zhuǎn)換為跨語言的控件。
  
   類工廠創(chuàng)建如下:
   {
          TActiveXControlFactory.Create(
            ComServer,
            TCheckListBoxX,  //派生類
            TCheckListBox,  //基類
            Class_CheckListBoxX, //派生類GUID
            1,
            LIBID_CLBX,  //COM服務(wù)器GUID
            0,
            tmApartment);
   };
  
   如果要給控件增加屬性可以使用標(biāo)準(zhǔn)的屬性頁:如下
  
    //標(biāo)準(zhǔn)屬性頁    CLSID   描述
   
    Class_DColorProgPage      用來編輯TColor屬性
    Class_DFontProgPage       用來編輯TFont屬性
    Class_DPictureProgPage    用來編輯TPicture屬性
    Class_DStringProgPage     用來編輯TStrings屬性
   
    要把一個或多個預(yù)定義的屬性頁添加到ActiveX控件中,必須定義如下,并加入到DefinePropertyPages函數(shù)中
    procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
   
    procedure TCheckListBoxX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
    begin
      {TODO: Define property pages here.  Property pages are defined by calling
        DefinePropertyPage with the class id of the page.  For example,
          DefinePropertyPage(Class_CheckListBoxXPage); }
      DefinePropertyPage(Class_ppgGeneral);      //添加自定義屬性頁
      DefinePropertyPage(Class_DStringPropPage); //添加標(biāo)準(zhǔn)屬性頁
    end;


//也可以自定義屬性頁,例如:TppgGeneral = class(TPropertyPage)
//自定義屬性頁--------------------------------------------
unit GeneralPage;

interface

uses SysUtils, Windows, Messages, Classes, Graphics, Controls, StdCtrls,
  ExtCtrls, Forms, ComServ, ComObj, StdVcl, AxCtrls;

type
  TppgGeneral = class(TPropertyPage)
    Label1: TLabel;
    ecColumns: TEdit;
    cbSorted: TCheckBox;
    Label2: TLabel;
    ecTabWidth: TEdit;
  private
   
  protected
   
  public
   
    procedure UpdatePropertyPage; override;
    procedure UpdateObject; override;
  end;

const
  Class_ppgGeneral: TGUID = '{3774F17A-5D73-11D3-B872-0040F67455FE}';

implementation

{$R *.DFM}

procedure TppgGeneral.UpdatePropertyPage;
begin
  { Update your controls from OleObject }
  ecColumns.Text := IntToStr(OleObject.Columns);
  ecTabWidth.Text := IntToStr(OleObject.TabWidth);
  cbSorted.Checked := OleObject.Sorted;
end;

procedure TppgGeneral.UpdateObject;
begin
  { Update OleObject from your controls }
  OleObject.Columns := StrToInt(ecColumns.Text);
  OleObject.TabWidth := StrToInt(ecTabWidth.Text);
  OleObject.Sorted := cbSorted.Checked;
end;

initialization
  TActiveXPropertyPageFactory.Create(
    ComServer,
    TppgGeneral,
    Class_ppgGeneral);
end.

2. ActiveXforms
 
   這個可以直接從AcitveX頁面選擇,AictiveXform對象來創(chuàng)建。其編程方式基本和普通的TForm一樣,它基本上就是為了
封裝一個獨立Tform到一個功能窗口而設(shè)計的??梢蕴峁┙o其他語言使用。例如網(wǎng)絡(luò)視頻瀏覽器,則可以用AcitveXform
來封裝一個畫面分割,視頻瀏覽等功能的窗口,即可在網(wǎng)頁上發(fā)布出去。只要注冊了該xxx.ocx(AcitveXform組件名),則
可以用任何語言打開,包括在網(wǎng)頁上打開。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多