delphi7 开发ActiveX的学习备忘录

来源:互联网 发布:腾讯企业邮箱域名设置 编辑:程序博客网 时间:2024/05/19 16:04

关于delphi7 ActiveX的学习备忘


步骤:

1、先创建ActiveX工程文件;

 2、注册ActiveX文件(ocx文件) ;

3、编写相应调用ActiveX文件(.ocx文件)的html文件.

具体操作流程如下:

步骤1:

a、选择File->New->Other ,ActiveX页面,选择ActiveX Form ;

b、填写New ActiveX Name:,其他的不用做变动(不好意思,我也不知道其他的什么意思);

c、成功创建ActiveX Form,保存工程,三个文件 (AAImpl1.pas、AAProj1.dpr加入ActiveX Name为AA);

d、AAProj1_TLB、AAProj1、AAImpl1;

e、增加接口(两种方法):

1、选中AAImpl1单元,即选中ActiveX Form,在delphi的Edit菜单中选择Add to Interface...;  

1> 在Add To Interface 窗口中加入接口Func:Function Func(x1,x2 :Integer) : Integer ;  

 2>最后OK就可以,delphi会自动帮你检查语法,如果语法或者参数类型或者返回值类型不对,delphi开发环境会自动给出提示。  

3>注意:该接口函数有两个参数 x1、x2,为Integer型 ,返回值也为Integer;  

4>参数和返回值类型说明:integer --long;String为BStr或者WideString ;

2、选中AAImpl1单元,即选中ActiveX Form, 在delphi的View菜单中选择Type Library;  

1> 在AAProj1.tlb 窗口中,在左侧列表中选择IAA,即选中IAA接口,右键->New->Method或者在在工具栏中选择New Method   ,接着给方法命名test;  

2>选中test,在选择窗口右边的Parameters页面,对该方法进行参数和返回值的进行增加,Return Type不需要改变;  

3>比如test的返回值为String,有一个String型的参数,则在Parameters中增加两个变量,具体如下    

   中文说明     Name       Type        Modifier     参数:      sVar       BSTR        [in]  //[in]表示输入参数     返回值:    sRet       BSTR*       [out,retvar] //表示输出结果,Type一定要为指针类型,否则出错,即一定要带*

     则AAImpl1中产生:     function TAA.test(const sVar: WideString): WideString;     begin      //编写函数体      result := sVar ; //此句为自己编写     end;  

 4>参数和返回值类型说明:integer --long;String为BStr或者WideString ;

f、增加属性Property:同样选中AAImpl1单元,即选中ActiveX Form, 在delphi的View菜单中选择Type Library;    在左侧列表中选择IAA,即选中IAA接口,右键->New->Property或者在在工具栏中选择New Property  ,接着给属性命名为Mystr,    在Parameters中修改Type为BSTR;   

 function TAA.Get_Mystr: WideString;   

 begin   //编写函数体    

end;

  procedure TAA.Set_Mystr(Value: WideString);  

 begin  //编写过程体  

 end;  

       以上为搭建框架,接下来在ActiveX Form上增加一个TButton(btn_AX)和一个TEdit(edt_AX)控件

g、回到AAImpl1页面代码窗口中,   

 function TAA.Get_Mystr: WideString;//得到 Mystr   

 begin   //编写函数体  

  Result := Self.edt_AX.Text ;  

  end;

  procedure TAA.Set_Mystr(Value: WideString);//设置Mystr  

begin  //编写过程体  

 Self.edt_AX.Text := Value ;  

end;  

 procedure TAA.btn_AXClick(Sender: TObject);  

begin  

 Self.ClickEvent(Self);

 end; 

ActiveX Form 编辑完毕,Project->Builder All Projects. //编译工程,生成AAProj1.Ocx文件。

 

步骤2:注册ActiveX文件(ocx文件) 两种方法注册ActiveX文件:

1、在delphi开发环境中,Run-> Register ActiveX Server //注册Ocx控件。

 2、开始->运行->regsvr32  "Ocx文件所在目录/AAProj1.ocx".

 

步骤3:编写相应调用ActiveX文件(.ocx文件)的html文件. 注:如果在delphi 7中可能会麻烦一点,至少我学习时是麻烦啦;方法:

1>Project->Web Deployment Options(Web部署选项)->Project ;

2>Target dir(Full path of the deployed OCX):选择或填写OCX的完整路径目录;   Target URL(Virtual path of the deployed OCX):填写 ./;   HTML dir(Full path of the deployed HTML file):选择或填写HTML文件的完整路径目录;   其他选项默认。   注:如果Web Deployment Options为不可用状态,则在File->New->Other->ActiveX->ActiveX Form接着删除掉这个ActiveX Form,此时Web Deployment Options为可用状态啦,他娘的,这种Bug 也有人能解决,真人才;

3>Project->Web Deploy ;

4>调试方法:Run->Parameters,在Local页面中  Host Application :C:/Program Files/Internet Explorer/IEXPLORE.EXE //你的IE在哪里就填写那里啦;  Parameters:文件路径/AAProj1.htm 调试运行即可以;

至此结束;


源自:http://blog.sina.com.cn/s/blog_137e6d7af0102vgls.html


0 0
原创粉丝点击