#1 2014-07-24 21:54:49

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

Class and form generating tool

I just made a simple class/unit/form generator tool.
Simply you create a CSV (E.g. MyObj.csv) file like so:

Code,RawUTF8,Edit,30
Desc,RawUTF8,Edit,512
ItemType,RawUTF8,ComboBox,30
Cost,Currency,Edit
LastCostD,TDateTime,DateEdit
VatCat,Integer,RadioGroup
Active,Boolean,CheckBox

Format:<Property/Field Name>,<Type>,<Control>[,RawUTF8 size for CDS]
And it will create units:

  • DataMyObj.pas (TSQLMyObj class)

  • MyObjFormU.pas (TMyObjForm class)

  • MyObjFormU.dfm

It will also make a TClientDataset on the form and add necessary fields to it, then create TDBxxxx versions of Controls specified (Edit=TDBEdit, etc) + code to get/set it from/to the TSQLMyObj class.
It is very immature and cannot handle Arrays, subobjects, etc. but it will at least create the bulk of your code and form.
Not intended to be full generator, just to create a skeleton of code/controls that you can copy to your project and edit normally from there on. Use RawUTF8 for unsupported types and just edit your code afterwards.

I'm not going to spend lots of more time on it soon, but I can see that in future:

  • More options like combobox/RadioButton listitems, MaskEdit, break a SET up into multiple CheckBoxes, and so on.

  • I might make the code generated 'template-able' so you can have different variations of forms that can be created (TObjectList-based instead of TClientdataset, HTML/JS/etc).

  • change name to CSV2ORM. smile

Can be found here:
ftp://ftp.true.co.za/TrueORMconv.zip

Last edited by AntonE (2014-07-24 22:05:35)

Offline

#2 2014-07-25 14:43:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Class and form generating tool

Great!

What do you think if we include it in the main source code repository?
We have the SQLite3\Samples\ThirdPartyDemos folder for this usage.

This won't be part of the official framework yet, since it is a work in progress, but it would benefit to be supplied within the main framework, on our repositories (both fossil and git).
I'm quite sure some other users would find it interesting, and perhaps add some features.

Thanks for sharing!
smile

Offline

#3 2014-07-26 16:49:26

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

Re: Class and form generating tool

I'd be honored, sure you can include it. But I think let me make some changes first, because as-is it's kind of scruffy to do just what I wanted quick and dirty.
I'll post back here if there's a bit more versatile version.

Regards

Offline

#4 2014-07-26 18:24:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Class and form generating tool

Great!

smile

Offline

#5 2014-07-28 08:05:59

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

Re: Class and form generating tool

Updated version 1.1 can be found on:
ftp://ftp.true.co.za/CSV2ORM1_1.zip

I included the compiled binary so users can use/test if they don't have Jedi library to compile.
Now supports:
Multiple templates with multiple files for each template, e.g. a form generates .pas & .dfm file.
Template-code editing in app. (Need to install syntax highlighter smile )
Comes with sample templates & CSV, just run and test.
Can generate different code for fields/properties/controls that have size limits (Strings) by using [Size] & [!Size] tags in template.

Still scruffy but a lot more versatile.
If anyone want a specific feature or find bug, please let me know.
Regards


Basic explanation:
Create code like:

type TSQLMyObj = class(TSQLRecord)
                          private 
                          [Fields]fMyName : MyType;[/Fields]
                          published
                          [Fields]property MyName : MyType  read fMyName write fMyName;[/Fields]
                          end;

or
[Controls] object LabelMyName: TLabel
    Left = 56
    Top = MyTop
    Width = 23
    Height = 13
    Alignment = taRightJustify
    Caption = 'MyName'
  end
  object MyControlName: MyDBControl
    Left = 84
    Top = MyTop
    Width = 121
    Height = 21
    DataField = 'MyName'
    DataSource = DS
  end[/Controls]

and it will expand to the properties/fields/controls you pass in CSV file.
It still needs a lot of changes but it's a good start and sufficient to create bulk of my repetitive code.

"MyObj" get replaced with your Object-name
"MyName" get replaced with property names, etc. See ReadMe file.

Last edited by AntonE (2014-07-28 08:20:49)

Offline

#6 2014-07-28 08:54:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Class and form generating tool

Nice!

I'm not a big fan of using CDS content as data source (due to the opaque data format), but it works.
Why not try to use our mustache template engine?

I've just included the source code to the SQLite3\Samples\ThirdPartyDemos folder of our repository.
See http://synopse.info/fossil/info/02f3aac603463a

BTW, what is ClientEngineU.pas unit?

Offline

#7 2014-07-28 10:09:42

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

Re: Class and form generating tool

Hi Arnaud,
yes CDS is also painfully slow but I like the briefcase-model/changelog so I still use it for now.

ClientEngineU.pas is just a unit where I centralize client components, basically where TSQLRestClient descendant resides so users should just edit that code to point to their TSQLRestClient unit/component. I'll make next version better commented and generic. + included sample template should be changed to generate any different unit/form/file you want. smile
Can now also generate non-DB components so I should be able to write a similar Livebinding template if needed, instead of CDS/Datasource-based form.

I never really planned this project, so a complete re-think might be needed for it to be a serious/proper tool...
I never worked with Mustache and thought it is just for HTML/JS. I'll check it out some time and revamp this, thank you.

Best regards
AntonE

Last edited by AntonE (2014-07-28 10:16:36)

Offline

#8 2014-07-28 10:13:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Class and form generating tool

Thanks for the info, and for sharing!

Offline

#9 2014-07-31 12:51:16

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

Re: Class and form generating tool

Please see
http://synopse.info/forum/viewtopic.php … 635#p11635
Where this is evolving into.

Offline

#10 2014-08-01 12:56:18

Junior/RO
Member
Registered: 2011-05-13
Posts: 207

Re: Class and form generating tool

AntonE, please put your project in a github account smile

Offline

#11 2014-08-01 18:12:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Class and form generating tool

The project is already in our GitHub account.

See https://github.com/synopse/mORMot/tree/ … mos/AntonE

Offline

Board footer

Powered by FluxBB