#1 2014-07-31 12:22:45

AntonE
Member
Registered: 2012-02-03
Posts: 74

TrueORM idea - High level MVC on top of mORMot

Please see CSV2ORM : http://synopse.info/forum/viewtopic.php?id=1911

TrueORM
A high-level Delphi ORM/MVC(?) built on top of mORMot.

It is an idea spawn from CSV2ORM, to expand on that, not all as described below is working yet, but it's the idea that count.

"The idea" is an app that (will have) have 3 parts:

  • Projects (Model| TSQLproject that contains Classes/Records)

  • Templates (View| TSQLTemplate that contains Mustache templates)

  • Scripts (Controller?| TSQLScript that contain Pascal/Javascript code)

You can have multiple projects. Each projects can contain a list of T_Class
"T_Class" each contain a list of T_Variable descendants, just like normal OOP.

A)Projects  (TSQLProject):
As a bare-bone start you create a new Project.
This project contain a list of T_Class that can be marked as either :
packed record
TObject
TSQLRecord

Classes (T_Class):
Classes contain a polymorphic ObjectList of T_Variables (properties/fields) descendants.

  • T_Variable       (abstract)

  • T_SimpleType     (abstract)

  • T_Integer

  • T_Float

  • T_Currency

  • T_Boolean

  • T_DateTime

  • T_String

  • T_Collection  (abstract)

  • T_Array

  • T_ObjectList

  • T_Class

The idea is to use only basic types, e.g. T_Integer but within T_Integer there are options to select if it's Int32/Int64, signed/unsigned, ENum, Set, etc.
Also e.g. there is only 1 DateTime type, but within it you set to use Date only, Time only or DateTime, Duration, high-precision, etc.
T_Array, T_ObjectList, T_Class variables let you select another T_Class from your project to created nested Classes.


USAGE: (Not all working yet, concept smile
As in CSV2ORM, import a text (csv) file like

User.csv:
UserName,String,Edit,50
Password,String,Edit,50

This will add a T_Class 'User' to you project. Mark it as a 'packed record'.

Now import Connection.csv:
FromIP,String,Edit,50
Started,DateTime,DateEdit

This will add a T_Class 'Connection' to you project. Mark it as a 'TObject'.

Now import Device.csv:
Name,String,Edit,50
Number,Integer,Edit
Users,Array:User,ListView
Connections,ObjectList:Connection,ListView

This will add a T_Class 'Connection' to you project. Mark it as a 'TSQLRecord'.

You have setup the model with nested DynArray/ObjectList. Alternatively you can greate quick/easy in the UI.

Each T_Variable can have a Control_Type associated to it. This is for UI generation, e.g. TEdit, TRadioGroup, etc. (Like in CSV2ORM)
This is still an 'not-good idea' as a UI mapping external to the model is needed, so you can have e.g. multiple forms where 'Device.Name' get TEdit or TLabel on one form, TCombobox on another, etc.

B)TEMPLATING (TSQLTemplate):
Similar to CSV2ORM, but more powerfull, using Mustache templates that can be edited in a JvHLEditor with syntax highlighting for many languages.
Here you will be able to setup multi-file templates (like in CSV2ORM) to create e.g.:

  • mORMot Data units/classes

  • Delphi units/forms

  • SMS forms (?)

  • HTML pages

  • SQL-scripts

  • Future idea: form creation, i.o.w. WYSIWIG

C)SCRIPTING (TSQLScript):
Also with HLEditor, able to create Pascal scripts (JvInterpreter) or Javascript (SpiderMonkey).
This code might be run in JvInterpreter or SpiderMonkey, but is intended to be able to create code snips that might be used in Templating.

Summary:
The notion of data, templates and scripting evolved naturally into a kind of model/view/controller concept, and the project's idea is still in 'alpha' phase.
I would like any ideas/comments if anyone find it interesting and have some insights that might be helpfull or thought-provoking.

I can see it possible to create a bare-bone client app that get only TSQLProject, TSQLTemplate, TSQLScript from server and can create it's own UI, scripts, etc. from that.
I.o.w. a client (and/or server) Delphi-app that is just a shell that generate UI-elements and can update without closing as forms/scripts is not compiled but sent from server via TSQLProject, TSQLTemplate, TSQLScript classes.


Regards
AntonE

PS: I should have part A (data modelling) finished in next day or two.

Last edited by AntonE (2014-07-31 12:55:45)

Offline

#2 2014-07-31 16:33:08

tech
Member
Registered: 2014-01-13
Posts: 107

Re: TrueORM idea - High level MVC on top of mORMot

Hi AntonE,

I think that is a very good idea and can give us the possibility to build true thin clients (or Universal wink ) with delphi. All the code source is on the server side and the thin client brings it to build the app at runtime.
These are some benefic points that I see :
1) Easy deployement for projects and updates (only on the server side) either for the .pas files than UI;
2) Universal client, the same for different projects;
3) Projects are customizable (different between users/customers);
4) There is no need to compile the source juste for UI modification;
and many others ...

The universal client is a dream for me for some years ago when I discovered the AS400 OS for the first time, because we don't have to deploy all apps on all client machines, juste the TN5250 must be installed to have the access to this famous plateform then apps/envirennoments are configured on the server side.
The universal client that I've in minde is the same as TN5250 but with UI, one time the user is logged on, he must chose the project to open from available projects.
I saw some tentative like the remotevcl from Paul TOTH, and thin client based on plugins (bpl) stored on firebird database but I can't find urls.

thnx a lot for sharing,

Offline

#3 2014-07-31 18:10:46

tech
Member
Registered: 2014-01-13
Posts: 107

Re: TrueORM idea - High level MVC on top of mORMot

I found remotevcl url on the web archive http://web.archive.org/web/201111142137 … tcp.rmtvcl

Offline

#4 2014-07-31 20:09:08

AntonE
Member
Registered: 2012-02-03
Posts: 74

Re: TrueORM idea - High level MVC on top of mORMot

Thanks tech,
yes I agree, a universal client as you call it can be very cool if done right, with mORMot's superior performance and flexibility, that might be a possibility.
However, I think this project is for now intended to be a.o. a code-generator helper tool, to generate code/units for you to prevent repetitive coding and maybe help generate multi-platform UI code for you as well (think .DFM and .HTML)
Also to help you handle things like enum/set in radio/checkboxes, higher-types like email,phone numbers, instead of just 'RawUTF8', and generating the UI code that goes with it, etc. Stuff I do manually all the time that is mindless, repetitive and annoying. big_smile
Because it use templates, you can do with it what you want, I'll use it to generate Delphi code that I can then manually fine-tune.
Scripting for now will be more to help generate custom code that cannot be easily represented via a templates, if at all.
Eventually it might evolve into a universal client/server, we'll see. smile

Thanks for your input

Offline

#5 2014-08-04 13:27:32

AntonE
Member
Registered: 2012-02-03
Posts: 74

Re: TrueORM idea - High level MVC on top of mORMot

I had a bit of a rethink. NOT a high-level MVC anymore (or yet), just a code-generation tool, but still very handy! Download & run sample to see possibilities.
A new version available.

ftp://ftp.true.co.za/TrueORM_1.2.zip
(binary included, so just download & run)

ReadMe:
TrueORM 1.2

Tool to help generate classes, units, forms, etc. from basic class/property info.

Quick start from sample:
1)Run TrueORM2
2)Click 'Load project'
3)Go to Project/Tasks tab. (Note Destination folder "FirstApp") Click 'Run tasks'.
4)In Delphi, open SampleApp.dpr from "FirstApp" sub-folder, compile/run! (Need JVCL)

Quick start from new project:
1)Give project name
2)Add classes, in each class, add some fields+controls
3)Add tasks to link project/classes to templates.
4)Save smile
5)Run tasks
(or just add new class to current sample project, link your new class to the task "Data&Lists", run tasks and see what happens smile )

TrueORM just wrote a whole app from basic info and mustache templates.

Detailed description:
Templates:
A template is a collection of related files. E.g. a form that has .pas & .dfm files but you can add many loosely related files(see sample 'Class list & Edit forms' that include mORMot Data unit, etc.)
Templates are separate from the project, so can be re-used in multiple projects.
Templates can be external files or embedded in the DB. Filenames are also mustache templates.
Apart from normal context variables in mustache, use translate to pass some custom variables, like {{"Top}} {{"TopAdd}} {{"TabOrder}} that is used in Delphi code to increment UI controls for DFM files.

Classes:
Classes contain a collection of Fields that is the input required to generate code.

Tasks:
Tasks is bringing the Classes and templates together and is where the actual code is generated.
If any classes are marked as 'Involved' in a task, then those classes will each be sent to the specified template, in turn, with just the Class(+fields) as mustache-context, e.g. for class editing-forms)
If a task does not 'involve' any classes, then the entire project is sent as mustache context to the template, e.g. for main-forms or app-wide templates like .dpr files.

Notes:
There are still few problems/bugs and I haven't tested all DelphiTypes in combination with all control types yet.
Since the app is generated from templates, you can create any type of app (client/server/firemonkey/etc.) or form, the ones included are just simple examples to illustrate possibilities.
The app is still far from perfect, but can be used to generate basic skeleton forms/units that can be copy/pasted/edited in your real app/project. (e.g. Memos, RadioGroups, etc. need to be manually resized in the generated form. packed record and Array/TObjectList support not working yet.)

Hope someone else can find it usefull.
Greetings

Last edited by AntonE (2014-08-04 13:37:19)

Offline

Board footer

Powered by FluxBB