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

2016/02/25

About Me

Hello there,

Welcome to my blog! My name is Eden Wu.

I am Software Developer with over 10 years of experience in the area.


I wrote some of the product shipped in commercial products such as: C++ Builder 6, Delphi XE, and Delphi XE7.

I'm the ONLY ONE Embarcadero MVP from Greater China!
In 2016 Embarcadero invited me to join a select group of Delphi experts from around the world to form the Embarcadero MVP program, to which fewer than 100 people worldwide have been admitted (I'm the only one from Greater China).


I am very proud to announce that Embarcadero has appointed me as one of their MVP(Most Valuable Professionals)!



I hope you'll enjoy your visit here.

=========================
歡迎!

歡迎你來到我的部落格,我是【大匠之風】的作者:「Eden Wu」。

我是一名資料庫應用程式開發者(軟體工程師),有超過十年的程式開發經驗。

過往曾以「C++ Builder 6、Delphi XE 和 Delphi XE7」,為服務的公司打造出符合其需求的商業應用程式。


大中華區唯一的 Embarcadero MVP!
在 2016 年,我獲得 Delphi 最高榮耀【Embarcadero 最有價值專家(MVP)】資格,在全球超過 100 名的最有價值專家中,在大中華區,我是唯一的【Embarcadero 最有價值專家(MVP)】。

我要驕傲的再次重申:我是 Embarcadero 認可的最有價值專家之一!

謝謝你來到我的部落格,也期待你能享受我的文章。

2016/02/23

Field common unit generator by Delphi

What is your code pattern? Like below:

MyDataSet.FieldByName(‘MyField’).AsString := something…;
MyDataSet.FieldByName(‘MYFIELD’).AsString := something…;
MyDataSet.FieldByName(‘myfield’).AsString := something…;

Like these codes in the maintenance often have lost a string or sensitive issues, so "Field common unit generator" application is born! as shown below:
Field common unit generator


How to connection?
“Field common unit generator” that uses ODBC, it cans connection any database.

“With Table”
It can select multi items to build source unit in right memo.

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

Why use “Field common unit generator”?

  • Elegant: You can call Code Insight when editor, this fast input and code is clear!
  • Correct: “Field common unit 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, if use DataSet.Fields in design, the program can increase the performance of more than 50%

Now, you could write code, like below:

ADataSet.FieldByName(TORDERColumns.EmpNo).AsString := something....;
or
ADataSet.Fields[TORDERIndex.EmpNo].AsString := something...;



You can download preview version: here!

2016/02/21

FireMonkey 學習日記05 -- 實現 Login 功能(下)

繼上回所做出來的結果:

結果輸入畫面會被虛擬鍵盤摭住,所以接下來就是參考【FireMonkey -- 實現 Login 功能(中) 】所提到的「KeyboardDemoForm」專案來解決這個問題


比較有意思的是,為了能方便在 Windows 下的 Debug,可以設定全域變數:

2016/02/20

FireMonkey 學習日記04 -- 實現 Login 功能(中)

原來官方的 Demo 裡有解決虛擬鍵盤擋住輸入元件的辦法

範例專案名是:KeyboardDemoForm

看了看原始碼,我認為是利用拉霸(Scroll Bar)來操作輸入欄位的處理

2016/02/19

FireMonkey 學習日記03 -- 實現 Login 功能(上)

繼昨日的 FireMonkey 範例專案後,就在這個專案上加點東西吧,就以 Login 功能來實作好了

首先,再加入 TTabControl,給了兩個分頁
在「LOGIN」分頁加入了 TLabel, TEdit 物件,畫面如下:

2016/02/18

FireMonkey 學習日記02 -- 從範例專案學分頁技巧

FireMonkey最原先的目標是在行動平台上,就以行動平台範例來學習吧!

專案精靈裡有個「Tabbed with Navigation」項目
Tabbed with Navigation
在這個專案中,我們可以學習到:

2016/02/17

FireMonkey 學習日記01 -- 多國語言嘗試

FireMonkey 裡有個 TLang 元件

主要是使用 TLang 裡的「Language designer」進行映射工作,如下圖:
博君一笑的成分很大


來試試看結果如何吧!

比較重要的是,標籤的部份沒有區分大小寫

英文版:


正體中文版:


意外的簡單用 ^_^

See also:

2016/02/14

讀書心得 -- 【資料庫設計ER Model基礎講座】

前一陣子為了修改舊專案裡的小問題,發生了以下的情形:
  • 修正了 A 問題,卻冒出了 B 問題
  • 資料計算結果一直都有問題,但程式碼到手上時就已經這個版本

於是我決定重寫這個專案的核心,然而遇到更悲慘的狀況:

2016/02/08

讀書心得--【劉備不是傳說】

繼【明朝的那些事兒】和【秦始皇:一場歷史的思辨之旅】後,終於有機會認真看完這一本書:【劉備不是傳說】

劉備不是傳說 圖片來源:博客來

說起劉備,大家不約而同的會勾起一個印象 -- 【一名把天下哭出來的君王】。

這比把長城哭倒的【孟姜女】還要生猛,然而孟姜女的故事只是傳說,更何況如果真有其人,以她的神話性,想要成為武則天第二,又或是東方版的【聖女貞德】,那也是非常有可能的事情。

2016/02/05

那些年 DBeXpress 所教我的事:DBXCommon 單元

今天是臺灣農曆年的最後一個工作日,也用技術文章作最後的收尾吧!
==============================


資料庫應用程式設計一直以來都是 Delphi 的強項之一。

Dbx 的目標是為了要讓所有資料庫存取方式統一,在核心上用了很多技巧。

在【dbExpress MetaData 徹底攻略】 文中便大量的應用到 DBX 的獨特設計方法。

例如:【如何取得資料表的所有欄位?】

How to use URLEncode in Delphi

URL編碼,也稱【百分號編碼(Percent-encoding)】 由於 URL 不能直接接受 UTF8 文字,所以要先轉成百分號編碼後,如此網址才能順利送給 HTTP Server 從 Indy 加入 Delphi 後,就可以用 IdURI.TIdURI 單元進行編碼 ...