ocx 的制作和使用

时间:2024-10-13 22:52:47

1、打开delphi2010,选择【file】→【new】→【other】

ocx 的制作和使用

2、选择【activex】→【ActivexLibrary】→【OK】按钮

ocx 的制作和使用

3、修改name为MyOcx.点击【SaveAll】按钮保存全部,保存文件名为PMyOcx.ridl。

ocx 的制作和使用

4、选择【file】→【new】→【other】→【activex】→【Activex Form】→【OK】按钮

ocx 的制作和使用

5、设置 coClass Name: OcxForm,再【OK】按钮

ocx 的制作和使用

6、【file】→【Save All】保存的文件名为UOcxForm

ocx 的制作和使用

7、现在给OcxForm 添加一个String 和Integer属性。选择PMyOcx.ridl单元。右击IOcxForm→【New】→【Property】。进入添加属性界面

ocx 的制作和使用

8、name 改成 Myint 。Type改成Int。刷新下这个属性。同样的方法添加一个string的属性。name :MyString,Type:BSTR

ocx 的制作和使用

9、打开UOCXFORM单元,给MyInt和MyString赋值和读取值。在private定义两个变量 MyInt,MyString。

ocx 的制作和使用

10、functio艘绒庳焰n TOcxForm.Get_MyInt: SYSINT;begin Result := MyInt;end;procedure TOcxForm.Set_MyInt(Value: SYSINT);begin MyInt := Value;end;function TOcxForm.Get_MyString: WideString;begin Result := MyString;end;procedure TOcxForm.Set_MyString(const Value: WideString);begin MyString := Value;end;设置以上属性。

11、接下来就给做intraweb做准备。打开PM鲻戟缒男yOcx_TLB。找到CLASS_OcxForm: TGUID = '{736D170C-B4B潮贾篡绐C-4855-AA52-E725E285FA90}';保存下来。

ocx 的制作和使用

12、选择【Run】→【Register Activex Server】,注册一下,正好在创建intraweb上使用。

ocx 的制作和使用

13、新建一个intraweb程序。【f坡纠课柩ile】→【new】→【other】→【VCL for the web】→【VCL for the web application wizard】 把project name 设置成Myocx 保存

ocx 的制作和使用

14、在iwform1上添加一个iwactivex.在其中的IWAppFormRende筠续师诈r事件中加入这样的代码,就可以向里面传参数了。pro艘早祓胂cedure TIWForm1.IWAppFormRender(Sender: TObject);var Myint: Integer; MyString: string;begin Myint :=8888; MyString := '8888'; IWActiveX1.ClassID :='clsid:736D170C-B4BC-4855-AA52-E725E285FA90'; IWActiveX1.CodeBase :='http://192.168.0.56:8888'+'/files/PMyOcx.ocx#version=1,0,2,1'; with IWActiveX1.Params.add do begin Name :='Myint'; Value := IntToStr(Myint); end; with IWActiveX1.Params.add do begin Name :='MyString'; Value := MyString; end;end;

ocx 的制作和使用
© 手抄报圈