Translate

ebook【Delphi跨平台資料庫程式設計火速上手】電子書出版 (CHT)

Delphi 跨平台資料庫程式設計火速上手,是本關於整合 Delphi 的跨平台技術打造 2-Tier 架構的跨平台 APP 的入門技術書。 全書沒有需要理解的技術知識,只講套路。 力求短時間把製作 APP 的工法熟悉,未來要開發其它的應用程式也能舉一反三。 底下...

2016/02/29

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?
Ex:
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

TField:

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

T*Field:

The mode is "Strong Field", like TStringField, TIntegerField, TFloatField etc. It's simple code like below:
  type T: class (T)
    Fid: TIntegerField;  
  public
    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
  public
    property id: Integer read getId write setId;
    property Name: TNullableString read getName write setName;


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

  // 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!

or

Windows 10 Store: Delphi ORM Generator

Enjoy it!!!

沒有留言:

張貼留言