ocx 的制作和使用
来源:网络收集 点击: 时间:2024-08-31打开delphi2010,选择【file】→【new】→【other】

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

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

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

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

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

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

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

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

function 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/14接下来就给做intraweb做准备。打开PMyOcx_TLB。找到CLASS_OcxForm: TGUID = {736D170C-B4BC-4855-AA52-E725E285FA90};保存下来。

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

新建一个intraweb程序。【file】→【new】→【other】→【VCL for the web】→【VCL for the web application wizard】 把project name 设置成Myocx 保存

在iwform1上添加一个iwactivex.在其中的IWAppFormRender事件中加入这样的代码,就可以向里面传参数了。
procedure 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;

版权声明:
1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。
2、本站仅提供信息发布平台,不承担相关法律责任。
3、若侵犯您的版权或隐私,请联系本站管理员删除。
4、文章链接:http://www.1haoku.cn/art_1175258.html