Using Delphi data-aware components - pros and cons [closed]
Asked Answered
W

7

17

I want to know your opinion about using data-aware components in projects. Which are the 'strength' and 'weak' points of developing applications(win32 and web), by using Delphi and data-aware components(from Delphi's standard suite or third-party)?

Using FireBird I've worked a lot with IBObjects, which are a mature suite of components and worked very well.

But there are also a lot of other RDBMS (MySQL, MSSQL, DB2, Oracle, SQLite, Nexus, Paradox, Interbase, FireBird etc). If you have developed big projects, on which you've used a lot data-aware components please answer with the database type and data-aware components suite name.

I'm also interested on DB2 (AS400). What components have you used with success, or which components are really a pain to work with?

Worst answered 18/1, 2011 at 9:41 Comment(0)
B
20

I've found that using the data-aware components results in an application with no clear distinction between business and UI logic.

This is fine for small projects but as they grow larger the code becomes less and less maintainable.

All the various bits of event code (and their interactions) can become a real nightmare to understand!

Invariably in such cases I've ditched data-aware components and have switched to a (hand-coded) MVC design.

This does require a lot of up-front coding effort but results (IMHO) in a project that is maintainable, extensible and debuggable.

Bandeau answered 18/1, 2011 at 10:16 Comment(4)
It's one of the limit of the RAD approach: nice to have something working quickly, but sometimes less powerful and maintainable than code oriented solutions.Hairline
+1 As a developer used to the "hand-coded" MVC style who is currently working on a data aware control, I can't agree more. There are huge amounts of repeated code, and sometimes a tangled mess of event handlers.Vano
I forgot to mention that for connecting to Oracle I've used "Direct Oracle Access" from allroundautomations.com. A great set of components if you want to use Oracle specific features. Of no use at all if you want to remain database agnostic.Bandeau
Note that it is not either-or. While my main business code was a MVC style framework (to support both web and clients), I still used the quick RAD approach for e.g. system administration tools.Concert
F
14

Having tried both data-aware and non data-aware style of Delphi applications I'm back in the data-aware component camp these days. It takes a bit of work and discipline to correctly layer the code but it's still quicker than doing everything by hand using non data-aware controls.

A few of my tips for data-aware component usage are

  • Don't just rewrite FishFact on a larger scale. Put some thought into your design.

  • Don't use a TDataModule, use many TDataModules each responsible for just a small aspect of your applications data.

  • TDatasets belong on TDataModules, while TDataSources belong on TForms (unless used for master/detail relationships).

  • Use in-memory datasets such as the DataSnap TClientDataSet.

  • Your ClientDataSets don't have to mirror your database tables exactly. DataSnap allows you massage your data structures in memory so you can produce datasets tailored for specific purposes. Specifically you can do things like

    • Joining two or more tables into the one editable dataset

    • Denormalizing master detail table structures, can simplify your UI code sometimes.

    • Create in-memory only fields (like calculated fields but you can write to them also)

  • TClientDataSet nested tables are useful but not the only way to express master detail relationships. Sometimes it's better to do it the old way with two independent TClientDataSets joined through a TDataSource.

Freedman answered 19/1, 2011 at 2:8 Comment(0)
H
6

Take a look at ORM solutions.

It's a nice approach with multi-tier architecture. See ORM for DELPHI win32

Hairline answered 18/1, 2011 at 10:28 Comment(0)
S
6

Data aware controls are great, but you have to make sure you get your business code in a separate layer.

That is not difficult, but you need to be aware on how you can do that.

One approach is to have your DataSet components in a DataModule (or other non visual container).

Another handy trick is to use a TClientDataSet to do the UI entry, and use that as an intermediate buffer between the UI and the business layer. The business layer then uses TDataSet components specific to your data layer.

--jeroen

Such answered 18/1, 2011 at 22:7 Comment(5)
Agreed. Using data-aware controls against an in-memory dataset such as the TClientDataSet is my preferred user interface model these days. It takes a bit of work and discipline to correctly layer the code but it's still quicker than doing everything by hand using non data-aware controls.Freedman
I think it might be initially quicker, but still, a net loss instead of a win in the long term.Eyetooth
@WarrenP please elaborate on that: I'd love to see your point on this.Such
I have always found that I expend less effort to get 90% done, and that the last 10% when I use data-aware controls always takes longer, especially where multilevel master/detail relationships exist in the system. Some of that comes from the tricks you need to learn to work with the data-aware model, and some of it comes from the strange glitches I encounter only when I use data aware controls.Eyetooth
@WarrenP so what is your approach on this? It might even warrant an own answer :)Such
P
3

Delphi data-aware components are not depended on the back-end database engine you are using, so using Firebird or MS SQL Server or Oracle or others doesn't matter to your data-aware components. They only know the datasource component assigned to them and do all their DB related stuff via that.

For me, if something can be done with data-aware components in a nice way, I will use them. These are usually small projects which should be done in a short-time. In bigger projects, I might totally rule out data-aware components or use them in forms that are merely used for data presentation and do not receive user input. When it comes to receiving user input, I might use non-data-aware components because I have more flexibility in controlling them and validate the input. Of course data-ware components can be still useful in such scenarios too. You still can validate user input in dataset events like OnBeforePost. Also if you are using a multi-tier design, and your client app represents data presenter layer, your input validation is done in the middle-tier so you can receive input using data-aware components in the client app, and send them to the middle-tier for validation and further processing.

Perfuse answered 18/1, 2011 at 10:36 Comment(0)
P
3

You can use Unidac which supports many database servers, including Firebird (that i use) and has very nice features.

Coupled with Remobject SDK you will have a nice combination of n-tier architecture and database abstraction.

Polyclinic answered 18/1, 2011 at 11:11 Comment(0)
C
3

Data-aware components are usful from a RAD and prototyping perspective, especially when you're designing reports or grids that are based on data. i.e. you can tinker at design time. So I use them like that. But when it comes time to transform it into shipping code, I almost always sever the connections, remove the SQL from the queries, and do everything in code. It's much more predictable and maintainable that way, especially in a multi-developer environment with version control. When the SQL is embedded in the form somewhere, it's a big pain to try to figure out where the SQL actually resides. And it's especially bad to have SQL in two places, and then have to figure out which is in effect.

Command answered 18/1, 2011 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.