使用Delphi进行数据库开发的最佳实践是什么?[英] What are the best practices for database development with Delphi?

本文是小编为大家收集整理的关于使用Delphi进行数据库开发的最佳实践是什么?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

  1. 我该如何有效地使用RAD(重用代码).任何 样本,现有库,基本 Crud发电机?
  2. 我该如何设计OOP?哪个 设计模式 连接,抽象不同 引擎/DB访问层 (bde-dbexpress-ado),基本crud 操作.

推荐答案

我有自己的Delphi/MySQL框架,使我可以很快地添加"新屏幕".我不会分享,但是我可以描述我采用的方法:

我使用带有基于TFRAME的层次结构的标签接口.我创建一个标签并将tframe链接到其中.

我要使用标准MySQL存储过程实现来照顾所有的CRUD管道和并发控制.客户,客户,客户,客户del等...

我的主要形式本质上包含了纳维尔面板和一个包含tpagecontrol的面板

我的层次结构中的类的示例

tframe TMFRAME-我的推导,接口实现捕获Onshow,Onhide和其他一些详细信息

- twebbrowserframe -tdataawareframe - tobjectedItframe -tcustomeredItframe -torderedItframe ETC... -tobjectListFrame -tcustomerListFrame

等...

和一些对话..

tdialog tmdialog -tdataawaredialog - tobjecteditdialog - tcontacteditdialog ETC.. - tobjectSelectDialog -tcontactselectdialog

等...

当我添加一个新对象进行管理时,它可能是客户的新属性,假设我们想跟踪客户拥有的车辆.

创建表自定义 我运行我的特殊Sproc Generator,该生成器会创建我的SEL,GET,UPD,DEL 测试这些...

来自我上面提到的基类,丢弃一些控件.将选项卡添加到tcustomeredit.

delphi始终将数据集作为抽象层,通过数据源将其暴露于您的GUI.将数据集添加到客户数据模块中,然后"注册".我自己的自定义功能在我的派生数据模块类中,tmdatamodule

在框架中类似地处理安全控制..i'注册'组件需要可见或启用安全标志.

我通常可以添加一个新对象,构建Sprocs,在一个小时内添加维护屏幕.

当然,这通常仅仅是开始,通常是在添加某些内容时,您将其用于跟踪.如果这是一个车库应用程序,我们想将客户带入车库中的车辆,以便我们可以跟踪历史记录.但是即使这样,也很快.

我曾尝试使用"新开发工具"将年轻人分包给年轻人,而当我说我可以使用Delphi更快地做这件事时,他们似乎从来没有相信我!我可以在两个小时内做任何事情,似乎花了两天的时间,他们仍然有错误...

做 - 请小心计划您的VFI!正如某人提到的那样,如果您想更改一个父级中的组件名称,请为麻烦做好准备.即使您清洁DCU,您仍然可以在层次结构中打开并"编辑"每个孩子,即使您仍然可以拥有一些DFM地狱.我可以在2006年向您保证这仍然是一个问题.

不要创建一个怪物datamodule

确实花时间在前期设计上,在创建大量的抚养人之后进行重构可能是一个有趣的挑战,但是当您必须快速努力工作时,一场噩梦!

其他推荐答案

如果使用"将每个DB对象放入一个大数据模块中"(或大型应用程序中的"几个大数据模块"),请非常小心.这可以使您的项目具有数据模块如此之大,以至于您必须使用HD Monitor来查看此Datamodule上的所有TXDATASET
底线:切换到使用专用类作为业务逻辑而不是大型全局数据模块.仅在很小的项目中使用具有逻辑的全局数据模块.

其他推荐答案

好吧,我强烈建议您在设计用户界面时使用操作(TactionList).有许多预定义的操作,包括可以在数据集上执行的Next/prev/insert/delete/edite/更新操作,因此,最好使用这些操作并将其链接到表格上的按钮/菜单.这样可以防止UI逻辑重复代码.

不需要Delphi的Crud Generator!将TDATASOURCE,TDBGRID和TACTIONLIST添加到表单中,将预定义的数据源操作添加到操作列表中,将这些操作链接到按钮或菜单,然后您完成!

本文地址:https://www.itbaoku.cn/post/597555.html

问题描述

  1. How can I use the RAD way productively (reusing code). Any samples, existing libraries, basic crud generators?
  2. How can I design the OOP way? Which design patterns to use for connection, abstracting different engines/db access layers (bde-dbexpress-ado), basic CRUD operations.

推荐答案

I have my own Delphi/MySQL framework that lets me add 'new screens' very rapidly. I won't share it, but I can describe the approach I take:

I use a tabbed interface with a TFrame based hierarchy. I create a tab and link a TFrame into it.

I take care of all the crud plumbing, and concurrency controls using a standard mysql stored procedure implementation. CustomerSEL, CustomerGET, CustomerUPD, CustomerDEL, etc...

My main form essentially contains navbar panel and a panel containing TPageControl

An example of the classes in my hierarchy

TFrame TMFrame - my derivation, with interface implementations capturing OnShow, OnHide, and some other particulars

--TWebBrowserFrame --TDataAwareFrame --TObjectEditFrame --TCustomerEditFrame --TOrderEditFrame etc... --TObjectListFrame --TCustomerListFrame

etc...

and some dialogs..

TDialog TMDialog --TDataAwareDialog --TObjectEditDialog -- TContactEditDialog etc.. --TObjectSelectDialog --TContactSelectDialog

etc...

When I add a new object to manage, it could be a new attribute of customers, let's say we want to track which vehicles a customer owns.

create table CustomerVehicles I run my special sproc generator that creates my SEL, GET, UPD, DEL test those...

Derive from the base classes I mentioned above, drop some controls. Add a tab to the TCustomerEdit.

Delphi has always the Dataset as the abstract layer, expose this to your GUI via DataSources. Add the dataset to the customer data module, and "register it". My own custom function in my derived datamodule class, TMDataModule

Security control is similarly taken care of in the framework.. I 'Register' components that require a security flag to be visible or enabled.

I can usually add a new object, build the sprocs, add the maintenance screens within an hour.

Of course, that is usually just the start, usually when you add something, you use it for more than tracking. If this a garage application, we want to add the vehicle the customer brought into the garage, id it so we can track the history. But even so, it is fast.

I have tried subcontracting to younger guys using 'newer development tools', and they never seem to believe me when I say I can do this all ten times faster with Delphi! I can do in two hours bug-free what it seems to take them two days and they still have bugs...

DO - Be careful planning your VFI! As someone mentioned, if you want to change the name of a component on one of your parent classes, be prepared for trouble. You will need to open and 'edit' each child in the hierarchy, even if you clean DCU you can still have some DFM hell. I can assure you in 2006 this is still a problem.

DON'T create one monster datamodule

DO take your time in the upfront design, refactoring after you have created a ton of dependents can be a fun challenge, but a nightmare when you have to get something new working quickly!

其他推荐答案

Be very careful if you use the „put every DB objects into one big data module” (or "few big datamodules" in huge applications) approach. This can make your project having data module so big, that you will have to use HD monitor to see all TXDataset on this datamodule
Bottom line: switch to using specialized classes for business logic instead of big global data modules. Use global data modules with logic ONLY in very small projects.

其他推荐答案

Well, I strongly suggest you to use Actions (TActionList) when designing your user interface. There are many predefined actions including Next/Prev/Insert/Delete/Edit/Update operations that can be performed on datasets, so it is a good practice to use these actions and link them to buttons/menus on your forms. This prevents repeated code for UI logic.

There is no need for a CRUD generator for Delphi!! Add TDataSource, TDBGrid and TActionList to a form, add predefined data source actions to the action list, link those actions to buttons or menus, and you are done!