Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2022-05

Design-time features for pas2js

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt

Hello,

I've committed initial design-time support for pas2js.

What does this mean ? This is not (yet) full-blown WYSIWYG support for creating webpages.

But you can create event handlers, use TDatasets visually etc, like you would for a normal application.

I've created some 10+ demos that show how to work with this:

https://www.freepascal.org/~michael/pas2js-demos/design/

For many (but not all) examples you can download the sources straight from the demo.

Of course, all demos have been checked in in GIT - under demo/design.

To work with them in design-time, you need the latest lazarus sources, and you must install the components/pas2js/components/pas2jscomponents.lpk package.

Once you do this, there is a new file type 'HTML Fragment', this is your 'Form' or 'Frame'.

It works by what I term a 'HTML-First' design:

It supposes a single-page application, which loads a html fragment into the main HTML page, under a HTML element you can specify (the "body" element by default).

This HTML fragment can be loaded from a HTML file at runtime, specified in the 'form' itself, or loaded from a central HTML template manager class. The form has a .lfm file associated with it, which is included in the browser and used to load your form - just as in a native IDE.

There are no 'controls' which you drop on the 'page'. Instead, all controls are in the HTML you created. This design allows you to use all the power of CSS to lay-out your page.

How then do you interact with the HTML if there are no controls to attach events to ?

A central component on the component palette is the THTMLElementActions component. This is modeled after the TActionList you can find in the LCL
- but it is not 100% the same. In this component you can add an action for each HTML element that has an ID (a wizard will scan the HTML and extract all IDS for you).

You can also use CSS selectors for targeting multiple action acts as a kind of mediator between the HTML and your code: you can attach event handlers to the various elements in the HTML page (every element with an ID), and allows you to get/set values for inputs. DB-Aware actions exist too: they couple a dataset to the HTML input elements.

The other components are based on the 'webwidgets' package which exists since quite some time, in which some fixes have been done to correct some issues when streaming the components.

In the company I work for, we've been working like this in Delphi with TMS Web core, and I can say that productivity does not suffer at all with this approach. (in fact, due to superior editing capabilities of Lazarus, the coding works even faster :-)).

I've started a WIKI page in the FPC Wiki:

https://wiki.freepascal.org/pas2js_designtime

This (both the components and the WIKI page) is a work in progress.

Enjoy,

Michael.

Sven Barth
to Michael Van Canneyt
Michael Van Canneyt wrote
I've committed initial design-time support for pas2js.

Great work, will have to play around with this a bit when I find the time (ha, good one... -.-).

I've created some 10+ demos that show how to work with this: https://www.freepascal.org/~michael/pas2js-demos/design/

Are you aware that the country examples display some entries with "?" replacement characters? E.g. "?land Islands (AX)", "C?te d'Ivoire (CI)" or "Cura?ao (CW)"? At least on Windows with Firefox 100.

Regards,
Sven

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 13 lines
Am 21.05.2022 um 22:45 schrieb Michael Van Canneyt: > I've committed initial design-time support for pas2js. Great work, will have to play around with this a bit when I find the time (ha, good one... -.-). > I've created some 10+ demos that show how to work with this: > > https://www.freepascal.org/~michael/pas2js-demos/design/ Are you aware that the country examples display some entries with "?" replacement characters? E.g. "?land Islands (AX)", "C?te d'Ivoire (CI)" or "Cura?ao (CW)"? At least on Windows with Firefox 100.

No, I was not aware.
I will check this. Probably a code page issue.
Thanks for pointing it out !

Michael.