Delphi7 developing an ActiveX Learning Memorandum

Source: Internet
Author: User

From: Delphi7 to develop an ActiveX learning Memorandum

About Delphi7 ActiveX Learning Memo

AUTHOR:5CAIDM, 2008-06-12

Steps:

1, first create ActiveX project files;

2, registered ActiveX files (OCX file);

3. Write an HTML file that calls the ActiveX file (. ocx file) accordingly.

The following procedures are described:

Step 1:

A, choose File->new->other, ActiveX page, choose ActiveX Form;

b, fill in the new ActiveX Name:, the other do not have to make changes (sorry, I do not know what the other means);

C, successfully created ActiveX Form, save the project, three files (Aaimpl1.pas, AAPROJ1.DPR joined the ActiveX name AA);

D, Aaproj1_tlb, AAProj1, AAIMPL1;

E, add interface (two methods):

1, select the AAIMPL1 unit, that is, select the ActiveX Form, in the Delphi Edit menu, select Add to Interface ... ;

1> joins the interface func:function Func (X1,x2:integer) in the Add to Interface window: Integer;

2> last OK, Delphi will automatically help you check the syntax, if the syntax or parameter type or return value type is not correct, the Delphi development environment will automatically give a hint.

3> Note: The interface function has two parameters x1, x2, is an integer, the return value is an integer;

4> parameter and return value type description: Integer--long; String is a BSTR or widestring;

2, select the AAIMPL1 unit, that is, select the ActiveX Form, in the Delphi View menu select the type Library;

1> in the Aaproj1.tlb window, select IAA in the list on the left, select the IAA interface, right-->new->method or select New method in the toolbar, and then name test;

2> check test, in the selection window to the right of the parameters page, the method of the parameters and return value of the increase, return type does not need to change;

3> For example, the return value of test is string, there is a string parameter, then add two variables in parameters, as follows

English description Name Type Modifier parameter: SVar BSTR [in]//[in] indicates the input parameter return value: Sret BST r* [Out,retvar]//Indicates the output, type must be a pointer type, otherwise an error, that is, must take *

Then the AAIMPL1 is generated: function taa.test (const svar:widestring): widestring; Begin//write function body Result: = SVar; This sentence for their own writing end;

4> parameter and return value type description: Integer--long; String is a BSTR or widestring;

F, add attribute property: Also select the AAIMPL1 unit, that is, select the ActiveX Form, select the type Library in the Delphi View menu, select IAA in the list on the left, and select the IAA interface, right-click->new-> property or in the toolbar to select New properties, and then give the attribute named MyStr, in the parameters to modify the type as a BSTR;

function TAA. get_mystr:widestring;

Begin//write function body

End

Procedure TAA. Set_mystr (value:widestring);

Begin//write process body

End

The above is the framework, then add a TButton (Btn_ax) and a Tedit (Edt_ax) control on the ActiveX form

G, back to the AAIMPL1 page Code window,

function TAA. get_mystr:widestring;//Get MyStr

Begin//write function body

Result: = Self.edt_ax. Text;

End

Procedure TAA. Set_mystr (value:widestring);//Set MyStr

Begin//write process body

Self.edt_ax. Text: = Value;

End

Procedure Taa.btn_axclick (Sender:tobject);

Begin

Self.clickevent (self);

End

The ActiveX Form has been edited, Project->builder all Projects. Compile the project and generate the Aaproj1.ocx file.

Step 2: Register the ActiveX file (OCX file) two ways to register the ActiveX file:

1, in the Delphi development Environment,run-> Register ActiveX Server//Registered OCX control.

2. Start and run->regsvr32 "OCX file directory/aaproj1.ocx".

Step 3: Write an HTML file that calls the ActiveX file (. ocx file) accordingly. Note: If in Delphi 7 May be a little trouble, at least I study is trouble; Method:

1>project->web Deployment Options (WEB deployment option)->project;

2>target dir (full path of the deployed OCX): Select or fill in the complete path directory of the OCX; Target URL (Virtual path of the deployed OCX): fill in./; HT   ML dir (full path of the deployed HTML file): Select or fill in the complete path directory of the HTML files; other options default. Note: If the Web Deployment options is unavailable, the ActiveX form is then deleted in the File->new->other->activex->activex form, at which point the web Deployment options for the available state, his Niang, this bug also someone can solve, true talent;

3>project->web Deploy;

4> Debug Method: Run->parameters, in the local page Host application:c:/program files/internet explorer/iexplore. EXE//your IE where to fill in there, Parameters: File path/aaproj1.htm debug run can be;

To this end;

The following is scripting for ActiveX and Web HTML Interactive content:

<HTML> <H1> Delphi 7 ActiveX Test Page </H1><p> should see your Delphi 7 forms or controls EMB Edded in the form below. <HR><center><P>

<object

Id=testactiveproj1

Classid= "Clsid:a215ef7e-1486-4c7a-8a5f-16c640d73c65"

Codebase= "./aaproj1.ocx#version=1,0,0,0"

width=350

height=300

Align=center

Hspace=0

Vspace=0 >

</OBJECT>

<body>

<script language= "JavaScript" >

<!--

function Onloadtime () {

Document.myform.txtdate.value=aaproj1.func (1,8);

Document.all.AAProj1.Mystr = document.all["Txttest"].value;

}

function Ontestclick () {

Document.myform.txtdate.value=aaproj1.func (52,8);

Document.myform.txtTest.value = Aaproj1.mystr;

}

</script>

<script language= "JavaScript" for=aaproj1 event=onclick>

Document.myform.txtTest.value = Aaproj1.mystr;

</script>

<body onload= "Onloadtime ()" >

<form name=myform><div align= "center" >

<input name= "Txttest" type= "text" value= "size=" >

<input name= "txtdate" type= "text" value= "size=" >

<input name= "btn" type= "button" value= "Test" onclick= "Onloadtime ()" Size= ">"

<input name= "btn1" type= "button" value= "click" onclick= "Ontestclick ()" Size= ">

</div>

</form>

</body> </HTML>

Delphi7 developing an ActiveX Learning Memorandum

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.