Original: http://www.mamicode.com/info-detail-471283.html
First, using Delphi XE2 to write the OCX control
1, File-new-other, in the New Items dialog box, select the Delphi projects-activex-activex Library
2, File-new-other, in the New Items dialog box select Delphi Projects-activex-activex Control, here to seal the Delphi Tstringgrid control, so choose ActiveX Control, and other settings can be set by dialog box.
- New properties, Methods for OCX
View-type library pops up a form with an extension of Ridl
A Cells property and a Methodtest method are defined here. Why are there two cells? That's because a read, a write, can be seen by the invoke kind property on the right side of the attributes page. There is also a property type that is the property. You can also set parameters via the Parameters page, after the settings are complete such as:
Get Parameters:
Put parameters:
Methodtest Parameters:
You can then press the Refresh button on the Ridl form to generate the method body:
Second, JS call
Code:
<HTML>
<HEAD>
<title>myactivex-methods, Properties, and events</title>
<script language= "JavaScript" >
function PropertyTest ()
{
Myactivex1.cells (2,2) = Stringinput.value
}
function Jsmethodtest ()
{
Alert (Myactivex1.methodtest ())
}
</SCRIPT>
<!--capturing the double-click event of the OCX control--
<script type= "Text/javascript" for= "MyActiveX1" event= "OnDblClick" >
<!--Insert script commands--
Alert ("The event has been captured! ");
</SCRIPT>
</HEAD>
<BODY>
<center>
Myactivex-methods, Properties, and Events Example
<p></p>
<object id= "MyActiveX1" width=500 height=200
Classid= "clsid:e61826b4-18b3-4e6d-aed6-78361961d29c" >
</OBJECT>
<p></p>
Input Parameter: <input TYPE = "text" name= "Stringinput" value= "" >
<input type= "button" Name= "Submit1"
Value= "Properties" onclick= "PropertyTest ()" >
<p></p>
<input type= "button" Name= "Submit2"
Value= "Methods" onclick= "Jsmethodtest ()" >
</center>
</BODY>
</HTML>
:
An example of the use of the OCX control properties, methods, and events has been completed.
JS calls Delphi to write the OCX control