#1 2011-06-22 11:58:24

migajek
Member
Registered: 2010-10-01
Posts: 89

Record generator tool

Hi,
since I'm using Delphi 7 Personal which has no tools for class autocompletion, I had to write my own pseudo-meta-language tool.

It simply works by specifying fields one by one like following:

name:str
age:int
weight:float

the result is complete class declaration code, including class name, private variables and published properties.

additionally each field might be marked with ";r" and/or ";w" flags which will cause the generator to use getter and/or setter respectively for specific field.


for example

Name:str
Surname:str
Phone:str;r;w
Age:int;r
Weight:float

results in

    TSQLPerson = class(TSQLRecord)
    private
        fName: UTF8String;
        fSurname: UTF8String;
        fPhone: UTF8String;
        fAge: integer;
        fWeight: float;


        function GetPhone():UTF8String;

        procedure SetPhone(const AValue: UTF8String);

        function GetAge():integer;
    published
        property Name: UTF8String read fName write fName;
        property Surname: UTF8String read fSurname write fSurname;
        property Phone: UTF8String read GetPhone write SetPhone;
        property Age: integer read GetAge write fAge;
        property Weight: float read fWeight write fWeight;

    end;



function TSQLPerson.GetPhone():UTF8String;
begin
    result:= fPhone;
end;

procedure TSQLPerson.SetPhone(const AValue: UTF8String);
begin
    fPhone:= AValue;
end;

function TSQLPerson.GetAge():integer;
begin
    result:= fAge;
end;

the tool has also ability to parse back from Delphi class declaration to meta-language, but it'll work correctly only if the code follows the pattern used for code generation (private variable: fFieldName, setters / getters: Get/SetFieldName etc etc)


Here's the link (binary + source):

http://code.google.com/p/synopse-sqlite … p&can=2&q=

Offline

#2 2011-06-22 18:02:57

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

Re: Record generator tool

Very nice!

You should certainly generate RawUTF8 instead of UTF8String, for proper UTF-8 handling.

Thanks for your input!

I'm thinking also of a similar generator, but for reverse engenering of a Database instead: from an existing DB, in whatever format (thanks to OleDB drivers of our mORMot), some mapping classes will be generated.

Offline

#3 2011-06-23 12:09:24

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Record generator tool

You should certainly generate RawUTF8 instead of UTF8String, for proper UTF-8 handling.

indeed, my bad.

ab wrote:

I'm thinking also of a similar generator, but for reverse engenering of a Database instead: from an existing DB, in whatever format (thanks to OleDB drivers of our mORMot), some mapping classes will be generated.

well, I guess you're quite busy developing mORMot, maybe I could take care of creating such a basic tool?
Yet, I don't think current version of SynOleDB is able to handle such a thing wink
// BTW, SynOleDB uses OleDB which breaks the compatibility with D7PE, since OleDB is not a part of PE version sad

Last edited by migajek (2011-06-23 12:11:56)

Offline

#4 2011-06-23 16:58:09

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

Re: Record generator tool

migajek wrote:

BTW, SynOleDB uses OleDB which breaks the compatibility with D7PE, since OleDB is not a part of PE version sad

This is good to know: I'll therefore import all OleDB needed interfaces into our unit, so that it will compile.

Are ActiveX and ComObj units part of PE version?

Offline

#5 2011-06-23 23:22:52

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: Record generator tool

ab wrote:

Are ActiveX and ComObj units part of PE version?

yes, both are available.

Offline

#6 2017-08-16 01:47:00

linbren
Member
Registered: 2017-08-11
Posts: 42

Re: Record generator tool

code.google.com cannot access in china , may i get this tool on github ?

Last edited by linbren (2017-08-16 02:50:07)


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#7 2017-08-16 04:42:07

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Record generator tool

@linbren, I think it's been included in the official mORMot package: https://github.com/synopse/mORMot/tree/ … qlite-demo


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#8 2017-08-16 07:57:33

linbren
Member
Registered: 2017-08-11
Posts: 42

Re: Record generator tool

thans to @edwinsn .

however , it seem too much rough to be a tool .


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

Board footer

Powered by FluxBB