COM程序编写入门(二)

来源:计算机等级考试    发布时间:2012-08-28    计算机等级考试视频    评论

  考试大计算机等级站整理收集:

  COM的理论

  以实例来讲COM的接口(Interface)是COM的核心,所有的COM接口都是通过IUnknown派生出来的,它告知客户那些接口是有效的,即已经被实现类说定义。它定义的一般方式如下:

  ISimpleInterface=Interface(IUnknown)

  Function GetName:String

  Procedure SetName(v_Name:String)

  End;

  如果在上面的接口中加入这样一行:

  ISimpleInterface=Interface(IUnknown)

  V_Name:String;

  Function GetName:String

  Procedure SetName(v_Name:String)

  End;

  这样是不被允许的,因为上面我们说到接口方法就像是一个占位符,需要实现类引出才有实际意义,v_Name:String这一句只是一个数据成员将永远无任何意义,如果要定义也只能在实现类中定义。

  现在举一个COM的例子,没有什么实际用处但至少说明问题:

  unit Unit1;

  interface

  uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;

  type

  TForm1 = class(TForm)

  Label1: TLabel;

  Edit1: TEdit;

  Button1: TButton;

  Button2: TButton;

  procedure FormCreate(Sender: TObject);

  procedure Button1Click(Sender: TObject);

  procedure Button2Click(Sender: TObject);

  procedure FormClose(Sender: TObject; var Action: TCloseAction);

  private

  { Private declarations }

  public

  { Public declarations }

  end;

  ISimpleInterface=Interface(IUnknown)

  Procedure SetValue(v_Value:Integer);

  Function GetValue:Integer;

  End;

上一页12下一页

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答