How to : Linking delphi and javascript

Pubblicato il: 14 febbraio 2019
sul canale di: How to : Tips and Trick
49
1

Linking delphi and javascript

How to create an ActiveX and link it to JavaScript in an HTML document.

With the Delphi Active Form it is easy to create an ActiveX (OCX)

component what can be integrated into programs like VB, VBA

(Word, Excel, Access, and Outlook), Delphi, C++, and in this case

the IE Web-Browser via a HTML document.

From the Delphi IDE File | New menu, display the New Item dialog box,

and from the ActiveX tab select the Active Form option.

The Active Form creates a new Active Form, which is a simpler

ActiveX control (descended from the TActiveForm) pre-configured to

run in a Web Browser. The ActiveX Control Wizard appears to guide

you through the creation process, allowing you to add controls to

the form. The Wizard creates an ActiveX Library project (if needed),

a type library, a form, an implementation unit, and a unit containing

corresponding type library declarations.

Enter the New ActiveX Name in the Active Form Wizard. Change the

Implementation Unit name and Project name as needed.

Choose the threading model to indicate how COM serializes calls to

your ActiveX control.

Note: The threading model you choose determines how the object is

registered. You must make sure that your object implementation

adheres to the model selected.

Before activate the OK button check the required Control Options.

For more information use the Help button.

Add a property:

Display the projects xx_TLB.Pas file. From the Edit Window hit the

F12 to display the .Tlb form.

Under the Project you will find the Interface entry. If you expand

the entry you will see several pre-created properties. Right click

in the outline area and select the New | Property option. Two

Properties is added to the outline: The get and the put Property.

Enter the name and the type for the Properties.

In the protected area of the Class you will find a function and a

procedure matching the new Property. In the implementation section

you also will find the two functions and procedure. Add the

appropriated code to the function and the procedure.



function TActiveXtest1.Get_Entry: WideString;

begin

Result := EditEntry.Text; // Read the TEdit text

end;

procedure TActiveXtest1.Set_Entry(const Value: WideString);

begin

EditEntry.Text := Value; // Set the TEdit text

end;



Add an Event:

Open the Event section in the outline and right click. Select the

New | Method option. Give the Method a name like OnSubmit.

Lets say you want to assign a button click on the form with the new

event. Insert the following code under the button click procedure.



procedure TActiveXtest1.ButtonSubmitClick(Sender: TObject);

begin



If FEvents Nil Then

Begin

FEvents.OnSubmit; // OnSubmit is the new event

End;

end;



Compile the application. From the IDE Run menu you can register and

unregister the ActiveX with the registry.

The IDE can create an HTML test document for you to test the ActiveX.



Delphi 5 ActiveX Test Page

You should see your Delphi 5 forms or controls embedded in the form below.









You can change the code base to use the OCX instead of the INF file:

codebase="C:/NTS/Check/CheckIt.Ocx"

The code base is where the ActiveX is located so if it is not

registered with the registry the Web Browser knows where to find the

OCX.

When loaded from a web-site the code base should point to the URL

where the OCX can be found.

codebase="\activex\checkit.ocx"

You need to read a write the ActiveX property, which can be done with

a VBScript:









Or it can be done with a JavaScript:







So fare so good. Now we get to the best part connecting the event

in the ActiveX OCX and the HTML document.

In the VBScript world you would do the following:









Conclusion:

With the Delphi Active Form you can easily develop ActiveX OCX.

Drop TEdits and TButtons on the form and you have input and output

to the OCX. With the .TLB form you can add Properties and Event

which can be connected to an HTML document via VBScript or JavaScript.


In questa pagina del sito puoi guardare il video online How to : Linking delphi and javascript della durata di ore minuti seconda in buona qualità , che l'utente ha caricato How to : Tips and Trick 14 febbraio 2019, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 49 volte e gli è piaciuto 1 spettatori. Buona visione!