Solved

Can OOP use TDBControls?

Posted on 1997-05-05
4
267 Views
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.
0
Comment
Question by:ricker
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
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,
  Michael
0
 

Author Comment

by:ricker
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?
0
 
LVL 1

Expert Comment

by:miv
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.


0
 

Author Comment

by:ricker
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++.


0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now