Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best practices for database development with Delphi?

  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.
like image 930
user114285 Avatar asked Jun 05 '09 12:06

user114285


People also ask

What is a Delphi database?

Delphi enables you to create robust database applications quickly and easily. Delphi database applications can work directly with desktop databases like Paradox, dBASE, the Local InterBase Server, and ODBC data sources.

What is SQL in Delphi?

In Delphi: TQuery TQuery has a property called SQL, which is used to store the SQL statement. TQuery encapsulates one or more SQL statements, executes them and provides methods by which we can manipulate the results.


2 Answers

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!

like image 115
Jason T Avatar answered Sep 21 '22 16:09

Jason T


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.

like image 39
smok1 Avatar answered Sep 23 '22 16:09

smok1