Introduction

<< Click to Display Table of Contents >>

Navigation:  Using script in HTML document >

Introduction

To use scripting library in HTML documents add htdefscriptadapter unit to uses list.

Scripts are defined in HTML document similarly to standard Javascript scripts, but with type attribute set to passcript or text/passcript.

Example:

 

<script type="passcript">
 procedure Test();
 begin
  document.getElementbyId('myid').innerHTML := 'test';
 end;
</script>

 

Note, that <script> tag with type set to passcript is necessary event if its content is empty, otherwise script adapter will not process elements and document events. This is done to prevent attempts of executing pascal script on normal HTML documents containing Javascript in elements events.

 

Predefined variables

Following variables are defined when script in running inside an HTML document:

 

document: THtDocument - current document

window : TControl - control that owns document (for example THtPanel)

this: TElement - current element

event: THtMouseEvent - processed event

dragged: TElement - dragged element (in drag events)

form: TForm - current form (if script is running inside HTML control placed on a form)

 

Custom variables

Any object variable can be registered in script adapter for use in script:

 

    THtDefScriptAdapter.RegisterObject(const Name: string; Value: TObject);