[Pas2js] HTML2Form tool: generate pascal class from HTML page

Michael Van Canneyt michael at freepascal.org
Sat Aug 29 09:22:35 CEST 2020


Hello,

For my daytime job (yes, luckily I still have one beside FPC ;)) 
we use both pas2js and TMS Web core to create web applications.

We use an approach which we call 'html first', that is: we create the pages
in HTML and use that in our pascal code. This is not quite what TMS Web core
does, they use the DFM file to create the html (although there are some
mixed forms available there too.)

In order to speed up the generation of the pascal classes that correspond to
a HTML page (the 'Forms' in lazarus/delphi speak) I created a tool that
converts a HTML file to a pascal class. The pascal class contains a field
for every HTML tag that has an ID associated with it. A method is generated
that binds the field to the HTML tag.

The types of the fields can be fully customized using a map file. The map
file maps tags/attributes to pascal class names.

The tool can also generate a .lfm/dfm file, so it is usable to create a
start form declaration for TMS Web core.

You can directly use this class or (better) create a descendent of it to 
implement your business logic.

The tool can also, based on some attributes (think: _click_="DoStartClick")
generate event handlers for the HTML events. Combined with the Lazarus IDE
'Implement abstract methods' refactoring, this makes it a breeze to create
your pascal 'forms' from a HTML file.

I have committed this tool to the pas2js repository, under tools/html2form.

It's minimally documented and explained in:
https://wiki.freepascal.org/pas2js_html2form

Enjoy,

Michael.




More information about the Pas2js mailing list