Can OOP use TDBControls?

Posted on 1997-05-05
Last Modified: 2013-11-23
Hello Experts:

I am fairly new to (real) OOD and OOP.  My background has been mostly Clipper projects (yeah, yeah, we all know Clipper is passe).  Nonetheless, I used all the power in Clipper (code blocks etc) to write code which was somewhat object oriented.  The apps I write are mid size multi-user financial, sales entry, inventory control and reporting systems for vertical markets.  To give an idea of size, some of our clients achieve 1,000,000 plus GL transaction records in a two year span.

I've gained a fairly good grasp of Delphi (2.0) but now I have an OOP question.

In the past, I would never think of placing database fields into a user interface, as the DBControls in Delphi suggest... i.e. To edit a customer, I would assign database fields to memory variables, then exchange upon an explicit post.  With Delphi, it seems one would place the TDBEdits (or the like), directly attached to database fields, onto the editing form, and then use the events from an implicit or explicit post to check validity.  This however, seems to skate away from OOP.

To wit, if you create a TCustomer class (which descends from a TAccount class), you would want the TAccount methods to take care of main account data, and TCustomer to handle customer specific attributes and tasks.  This implies that the form on which a customer gets edited should retrieve field values from a TCustomer object, using TCustomer AND TAccount methods, and likewise post back changes.

Using DBControls, however, seems to bypass such a object based hierarchy, unless I am missing something.  Hence my question.

To maintain an Object Oriented Design, should I be using DBControls for editing objects such as Customers?  If so, would this preclude the use of a TCustomer class while editing the account?  Alternatively, am I better using TEdits, where the form retrieves initial TEdit values from a TCustomer object, which in turn handles all data access, validity, etc.

I have given this question 100 points.  If a truly comprehensive response is in order (as I expect), I will raise the points so I might learn, through your wisdom, the correct methodology.

Thanks in advance.
Question by:ricker
  • 2
  • 2

Accepted Solution

miv earned 100 total points
ID: 1335923
I would NOT use Delphi´s DB Controls.

Make your objects and use a procedure to transfer to and from your user interface.

Let each object have a virtual putdata and getdata function which handles the DB part of the transaction.

I have done this a lot of times, and it just works. You have full control over data, validation and can maintain the OOP idea in your objects.

Hope this helps,

Author Comment

ID: 1335924
I graded miv's answer as a 'C'.  Reason: I did get an opinion, but  I also only got a regurgitation of what I already know can be done.  I posed my question in a way which I hoped would have elicited a response which clearly states the pros and cons of the alternatives.  I still have the question in my mind...  Why did Delphi spend so much time developing all those DBControls?  And why is spending the time building "getdata" and "putdata" methods worth the effort?

Expert Comment

ID: 1335925
If you´re making "small" programs or using prototyping, the DB controls are very easy and fast to use.
They fits perfectly with the RAPID application development concept of Delphi.

BUT, if you developing a big (>30-50000 lines of code) application, you WILL run into some MAJOR problems along the way.
It will be very difficult to correct errors, re-use code or make a good object oriented program. It´s also very complicated to make team development, if you´re using DB controls or visual design (DFM files).

It´s my experience that visual design (drag and drop) is good for prototyping or very small programs, but if you serious about your program you have to use "hand-coding". It will benefit you in the long run.


Author Comment

ID: 1335926
Thanks for your comments miv....
It still disturbs me, now that I have invested so much time in learning Delhi, that it appears all the RAPID tools are really no good for REAL development.
And that being the case, I don't know why I just shouldn't be switching to C++.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question