国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Delphi > 正文

Delphi中實現界面與業務邏輯的分離

2019-11-18 18:17:57
字體:
來源:轉載
供稿:網友

Delphi中實現界面與業務邏輯的分離

                                                       J雪(zhuam)ndeveloper@sina.com

在做Delphi軟件開發之前,我從事java軟件的開發工作,從Java開源社區我學到了很多軟件的設計理想,這也許就是我從Java那里得到的回報啊! 開闊了眼界!

最近的項目是用Delphi開發,所以我又看起了Delphi,一個月的時間里我看了差不多看了4本Delphi方面書籍,在做Delphi項目的時候我更是用DELPHI的語法,JAVA的思想來進行軟件的開發與設計,感覺有些累!啊,閑話少說啊,進入正題吧!

DELPHI是一個快速軟件開發的IDE,通常的PRogrammer 都是先畫View(界面) ,然后在在相應的事件里面書寫Source Code,看事例:

1、比如我要向數據庫中插入一條記錄,通常的做法是這樣吧!

SQL Example:  Insert   Into   ExampleTable1 (Field1,Field2,Field3) Values(Values1,Values2,Values3)

現在假設這個DELPHI窗體上有三個TEXT控件,Name分別為 Frist,Second,Three

下面我用三種不同方法將數據插入到數據庫中:

1、直接插入
client  ---------->  Database

Insert   Into   ExampleTable1 (Field1,Field2,Field3) Values(Frist.text,Second.text,Three.text)

2、間接插入
 client  ---(Text傳遞)--->  dataClass ------->  Database

意思是先將該窗體數據保存到一個數據類中去,然后在由用戶從這個數據類中取數據,將這些數據
傳到數據庫中去

注意:
窗體控件是直接通過TEXT將數據存儲到(dataClass)數據類中去的。
這個dataClass只是用于存儲數據狀態的,里面全是屬性,沒有業務邏輯的實現!

如下:
{---------------------------------------------
  author:zhuam
  date:2004/09/04
  type:class
  property:all AssociatorRunBean Information Set Mothed
  descripte: 用于保存會員的行駛證信息 ,
-----------------------------------------------}
type
  TAssociatorRunBean=class(TObject)
  private
    FKiloMetre: Double;
    FCarNumber: string;
    FNumber17: string;
    FCarColor: string;
    FAssociatorID: string;
    FCarCapacity: string;
    FFrameNumber: string;
    FEngineNumber: string;
    FAvailabilityDate: TDate;
    FRegisterDate: TDate;
    FBackPicture:TImage;
    FFrontPicture: TImage;
    FLeftPicture: TImage;
    FRightPicture: TImage;
    function getBackPicture: TImage;
    function getFrontPicture: TImage;
    function getLeftPicture: TImage;
    function getRightPicture: TImage;
    procedure setAssociatorID(const Value: string);
    procedure setAvailabilityDate(const Value: TDate);
    procedure setBackPicture(const Value: TImage);
    procedure setCarCapacity(const Value: string);
    procedure setCarColor(const Value: string);
    procedure setCarNumber(const Value: string);
    procedure setEngineNumber(const Value: string);
    procedure setFrameNumber(const Value: string);
    procedure setFrontPicture(const Value: TImage);
    procedure setKiloMetre(const Value: Double);
    procedure setLeftPicture(const Value: TImage);
    procedure setNumber17(const Value: string);
    procedure setRegisterDate(const Value: TDate);
    procedure setRightPicture(const Value: TImage);
  public
    constructor create;
    destructor destroy;override;
    property  AssociatorID:string read FAssociatorID write setAssociatorID;    //會員號碼
    property  CarNumber:string read FCarNumber write setCarNumber;             //車牌號碼
    property  CarColor:string read FCarColor write setCarColor;                //汽車顏色
    property  CarMode:string read FCarColor write setCarColor;                 //車型
    property  EngineNumber:string read FEngineNumber write setEngineNumber;    //發動機號碼
    property  FrameNumber:string read FFrameNumber write setFrameNumber;       //車架號
    property  CarCapacity:string read FCarCapacity write setCarCapacity;       //排量
    property  Number17:string read FNumber17 write setNumber17;                //17位號
    property  KiloMetre:Double read FKiloMetre write setKiloMetre;             //公里數
    property  RegisterDate:TDate read FRegisterDate write setRegisterDate;     //注冊日期
    property  AvailabilityDate:TDate read FAvailabilityDate write setAvailabilityDate; //有效日期
    property  FrontPicture:TImage read getFrontPicture write setFrontPicture;
    property  BackPicture:TImage read getBackPicture write setBackPicture;
    property  LeftPicture:TImage read getLeftPicture write setLeftPicture;
    property  RightPicture:TImage read getRightPicture write setRightPicture;

end;

Insert   Into   ExampleTable1 (Field1,Field2,Field3) Values(AssociatorRunBean.Frist,AssociatorRunBean.Second,AssociatorRunBean.text)

3、間接插入
 client  ---(自定義property傳遞)--->  dataClass ------->  Database

意思是先將該窗體數據保存到一個數據類中去,然后在由用戶從這個數據類中取數據,將這些數據
傳到數據庫中去

注意:
窗體控件是直接通過的自定義property將數據存儲到(dataClass)數據類中去的。
這個dataClass只是用于存儲數據狀態的,里面全是屬性,沒有業務邏輯的實現!

Insert   Into   ExampleTable1 (Field1,Field2,Field3) Values(AssociatorRunBean.Frist,AssociatorRunBean.Second,AssociatorRunBean.text)

說到這里有人會問我,這樣實現有什么意義哩!細心的同志也許已經有所察覺啊!
這正是完成Delphi界面與業務邏輯的分離的一種手段啊

 

 

 

 

 

 

 


上一篇:用Delphi對SQL-DMO進行封裝的一種實現

下一篇:Delphi的編碼規范

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 琼结县| 木兰县| 襄垣县| 乐陵市| 平远县| 丰都县| 汝阳县| 黎城县| 大同县| 宁南县| 体育| 调兵山市| 泸溪县| 台山市| 察雅县| 新兴县| 洪湖市| 松溪县| 孝义市| 西藏| 永平县| 蒙山县| 黄平县| 庐江县| 扎兰屯市| 宜君县| 保定市| 海阳市| 仪陇县| 芒康县| 武山县| 茌平县| 交口县| 资讯 | 五原县| 佛教| 扶沟县| 民丰县| 江陵县| 年辖:市辖区| 肇庆市|