Delphi ORM Generator

Can Delphi do it?  Photo source

What is your code pattern? Like below:

MyDataSet.FieldByName(‘MYFIELD’).AsString := something…;
MyDataSet.Fields[n].AsString := something…;

Why can not used ORM(Object-relational mapping) code in Delphi?
Employee.EmpNo := 1;
Employee.Name := 'Eden';

Because TDataSet! It's always only one mapping method: FieldByName. You are always only to use:

  1. IDE design mode, drop down TDataSet...
  2. Open TFields box, append all fields...
  3. Type innumerable "FieldByName" and "Fields" in Editor...

That is not your best solution, ever!

You need "Strong Type"! It is like String, Integer, Double etc!

  Strong Type is...   Photo Source

So "Delphi ORM generator" application is born! as shown below:
Main page

The demo is used MyBase

How to connect?
“Delphi ORM generator” that uses ODBC, it can connection any database.

“With Table”
It can select multi items to build source unit in right memo. (Select only one Table in current version)

“With SQL” and “By MyBase”
It provides analysis SQL statement / MyBase data to build source unit (Only one table).

Why use “Delphi ORM generator”?

  • Elegant: You can call Code Insight when editor, this fast input and code is clear!
  • Correct: “Delphi ORM generator” out the code is hard-coded, so you can aware be wrong if typing a spelling errors in Design mode.
  • Efficient: Besides quickly type, your program can increase the performance of more than 53.73%

Delphi ORM generator have 3 Field mode selector:
  • TField
  • T*Field
  • Native Type


The mode is easy mapping about property to field, it's simple code like below:
  type T: class (T)
    Fid: TField;
    property id: TField read Fid;


The mode is "Strong Field", like TStringField, TIntegerField, TFloatField etc. It's simple code like below:
  type T: class (T)
    Fid: TIntegerField;  
    property id: TIntegerField read Fid;
Use be like:
  Emp: TEmpRow;
  Emp.Id.Value := 1; // The Value is Integer type, it's Strong Type! 

Native Type:

The mode is "Strong Type" and support "NULL" value, if field IS_NULLABLE is True in database table. It's simple code like below:
  type T: class (T)
    Fid: Integer; //Primary Key, IS_NULLABLE = False
     FName: TNullableString; // IS_NULLABLE = True
    property id: Integer read getId write setId;
    property Name: TNullableString read getName write setName;

The mode, you could write code, like below:
  LEmpRow: TEmpRow;
  n: Integer;
  n_str: string;
  LEmpRow := TEmpRow.Create(YourDataSet);
  // Control original DataSet methods.
   if LEmpRow.DataSet.Locate(EMP_ID, 100, []) then Break;
   LEmpRow.DataSet.RecNo := n;

  // Control row field method.
  LEmpRow.Id := n; // Right
  LEmpRow.Id := n_str; // Compiler Error: The property is Integer!

  LEmpRow.Name := nil; // Can input nil!
  if LEmpRow.Name.HasValue then // Output need check NULL
    n_str := LEmpRow.Name.Value; // Get Value method.

You can download preview version: 7z Version!


Windows 10 Store: Delphi ORM Generator

Enjoy it!!!



Delphi 自動化 JSON 格式相容性分析

Delphi 自動化產出的 JSON 格式一直被詬病著,因為它的 JSON 格式在起始處一定會強制寫入「Meta Data」,它看起來像是: "table":[["EmpNo",6,0,0,0,4,0,0,false,false,...