Link to home
Start Free TrialLog in
Avatar of AndersWP
AndersWP

asked on

Why is there a TDataSouce?

Something which has puzzled me ever since Delphi first came out:

What is the reason for having a DataSource class?

It seems to me data data-aware components and other users of datasets might just refer directly to the dataset in question. What is gained by having a DataSource in between?

Has anyone seen the light, or perhaps talked to someone from Borland/Inprise/Corell/(I wonder what comes next) about it?

Just curious...

Regards,
AndersWP

Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

???
TDataSource provides an interface between a dataset component and data-aware controls on a form.

Avatar of kretzschmar
hi all,

just from the delphi online help:

Description

Use TDataSource to provide a conduit between a dataset and data-aware controls on a form that enable display, navigation, and editing of the data underlying the dataset.

All datasets must be associated with a data source component if their data is to be displayed and manipulated in data-aware controls. Similarly, each data-aware control needs to be associated with a data source component in order for the control to receive and manipulate data.

Data source components also link datasets in master-detail relationships.

meikl
Avatar of florisb
florisb

pratical; you can use one datasource and have serveral queries using it. Otherwise there would be overhead.

Floris.
Hi all,

It seems to me the essence of a question is not in what does a DataSource, but why it exists (it is possible to build Delphi without it).

In my opinion, it is very convenient to separate visible controls from an actually source of data. I frequently make the forms which do not contain DataSet but only DataSorce. And it very simply to attach in runtime all of DataAwareControls to an actually source of the data.

Cheers,
Igor.
Avatar of AndersWP

ASKER

Well, guys (I presume), the points you bring up are of course all correct, but I still do not think they answer the question.

So let me put it another way:

Suppose for a moment that there was no TDataSource class in VCL, and that data-aware components and other dataset users in stead of the present DataSource property had a DataSet property. What would be lost in functionality/flexibility/...?

In other words, would we miss it, and conversely, what is the justification for introducing it?

Just for completeness, let's look at the issues you raise:

ITUgay and kretzschmar (DataSources are necessary glue between DataSets and data-aware components):
This seems like an insufficient argument to me. DataSources are necessary because VCL defines them so. This does not explain why VCL defines them as necessary.
 
florisb (Practical, multiple users per dataset):
Again, the same thing is readily achieved without the DataSource class. In fact, you can have several DataSources connected to each DataSet.

So, what do you say? Am I mistaken?

Regards,
AndersWP
Hmmm.....
I never reflected in its necessity, and simply used. Probably it is any vestige (but convenient) of the past.

Cheers,
Igor.
A possible use would be in this scenario.

You have a table, dataset and grid.

You want to use the program to update the table whilst the grid is disconnected.  To do this you just disable the dataset.  If you didn't have a dataset you would have to disable the table to turn the grid off, then wouldn't be able to update the table.

This is a really poor excuse as you could just use 2 tables to achieve this, but it is a possible explanation.

Dave.
I guess in the scenario you describe you could also use the DisableControls/EnableControls methods of the DataSet to do what you describe (and by the way, I guess you really mean DataSource when you write DataSet).

Regards,
AndersWP
For example, you can have many controls attached to one DataSource and more than one table (DataSet). If you want to display data from different tables the same way, you can simply change the DataSource.DataSet property and all controls will refresh displayed data.
Without DataSource you would have to change DataSet property of every control.

Another example you can get in Delphi Demos: look at the MastApp. You can see there the using a DataSource you can have 1 Navigator on your form and use it to manipulate data from different DataSets, f.e. Master - Detail.

Regards,
Kot.
I'm not sure we can give you a definitive answer to satisfy your curiosity, since none of us were originally part of the design team for Delphi.  It is probably quite possible to build a language without the datasource class, BUT you would also find yourself writing code to perform the exact functions which this class provides; e.g.  provide the link between the data stored in the tables, and the data displayed to the user.  I tend to think in layers of software....so, this datasource 'layer' would have to be duplicated in every dataaccess or datacontrol component.  Hence, my GUESS is that the authors of Delphi created  the datasource layer to provide a convenient way to segment the functions performed by each class [i.e. dataaccess and datacontrol].
Simple: While designing an application it is nice to see data in your data aware components, so you set the datasource property in the control to see the live data.
.....otherwise, you don't need the TDataSource Component.........
I guess we have come as far as we are going to get on this question.

My conclusion of the discusstion would be that in some circumstances (many dataware components looking at one datasource, the concrecte datasource varies at runtime), the DataSource is useful. Otherwise, it is mostly decorative.

This question was not intended as a point-earning excercise, but never the less, there is the formidable amount of *10* points to be gained. I have drawn lots between the participants, and the lucky winner is...(suspense)... chumba.

Thanks guys for sharing your views on the subject.

Regards,
AndersWP
ASKER CERTIFIED SOLUTION
Avatar of chumba
chumba
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial