Delphi component question

I want to write a component that takes a TADOConnection and returns a TADODataset.  The component will hide all the database access from the coders. See the code below.

This component (TDBPlatform) will return a dataset of all the users in the system but because I want to hide the sql and tables from the coders I would like to do it in a component.

My question is how do I make the TDataset property (Users) visible to any TDatasource component I drop on my form?

At the moment I do not seem to be able to assign the Users property to my TDatasource component. Its not availble in the list of datasets.  Is it possible?  I want to be able to link my TDBPlatform component and TDatasource component at design time.

TDBPlatform = class( TComponent )
     ... some code ...

    property ADOConnection : TADOConnection  read FADOConnection write SetADOConnection;

    property Users: TADODataSet read FUsers ;


    constructor Create( AOwner: TComponent ); override ;


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
You should create a datamodule instead of a component.

That way, you drop the ADOConnection, dataset etc like on any form, and just by adding the unit in your uses of other forms, you will be able to select the dataset from any datasource.

by the way, why not add the datasource in this datamodule ?

If you want to keep your component (or plain object) approach, you will have to assign the dataset (or datasource) by code to your other components.
soozhCEOAuthor Commented:
do u mean that I create a new component based upon TDataModule?  Should I use this as a data module? I guess its possible to have two or more datamodules?  What is so special about the tdatamdule component?
Emmanuel PASQUIERFreelance Project ManagerCommented:
you can create a DataModule exactly the way you would create a form, except that only non visual components can be placed on it. It's main purpose is exactly to do what you are trying to do : gather non-visual resources and expose them to the rest of your application. You can of course have more than one.
Go in File -> New... and select Data Module. You will quickly understand what to do because that really is like a form.

you can add methods and properties like any object, usually to perform standard things with the objects you have. In short, that's a good way to gather consistent piece of functionalities of your application, or better yet for many applications needing the same kind of resources.

Much like TFrame, if you don't know about them, they are the equivalent of datamodules but with visual components as well (think of Tframe like 'templates' for piece of a form that might appear more than once in an application or in many applications.

Using Datamodules and Frames everywhere you can is the best way to make re-usability reach a new level (after standard units regrouping standalone functions)
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

soozhCEOAuthor Commented:
Yes i realise that Tdatamodule is proper class to build this on but I am using Intraweb and wonder what the implications of that are.  Reading the Intraweb Manual it says that the TUserSession class is based on TComponent but it behaves like a datamodule.

Do you know anything about that?  
Geert GOracle dbaCommented:
what you are looking for has been described by Marco Cantu.
It's TDBRoot
you basically create a TUsers
this class contains all methods to insert/update/delete/select users
not a lot of it was published on the net though

it's basically a Smart SQL (just give that the Table name and the component does the rest)
some other dutch people when this way too: (also called business objects)
this one contains the pro and enterprise version of it
soozhCEOAuthor Commented:
I have tried to create a package with a custom datamodule in... but i can not find out how to add it to the IDE in Delphi RAD 2010.
Emmanuel PASQUIERFreelance Project ManagerCommented:
a DataModule is not a component that will appear in your component palette. You just have to add the unit in your project and create the datamodule like a form
Geert GOracle dbaCommented:
look for RegisterModule in the designer packages
soozhCEOAuthor Commented:
yes RegisterModule is what i need, but the second parameter should be TDataModuleDesignerCustomModule and i can not find that anywhere.  I am using delphi rad 2010.
Geert GOracle dbaCommented:
i went to back to read your question
the thing that bogged me was: why do you need a TDataModule at all ?
answer: you don't

you want your component to be visible from a TDatasource in the designer
solution to this is to let it descend from a TDataset
like a TAdoQuery - TAdoDataset - TCustomAdoDataset - TDataset

you could write your own descendant from TDataset --> will take a while

or use TAdoQuery and descend from that
and then hide all the methods/properties in the private section which you don't want to show

but why this level of protection ... ?
soozhCEOAuthor Commented:
if we go back to my original question you can see that i already have created a component with a TADOConnection and a TADODataset as published properties.

All I want to do is connect my TADODataset set to a TDatasource at design time.  I can connect the TADOConnection without problem... but not the TADODataset.  Is it possible?
What about requiring the call to your component's create to provide a TADODataset as well as the TADOCOnnection.  Then, you provide the background work to populate the TADODataset.  You'd need a mechanism to indication what the datasource (as in server and table/query/SP) is that is to be used to populate the datasource but that could be done by creating some constants that the developer would pass along with the connection and datasource parameters.
For instance:
Stupid Loatus Notes posted when I was trying to continue typing! :-(

For instance:
  LOANS       = 1;
  POLICIES  = 2;
  CLAIMS      = 3;
That way, the developer can "ask" for what  is wanted but doesn't necessarily have any knowledge of where it comes from and whether it is from 1 table or N tables.
Geert GOracle dbaCommented:
you need to descend from TAdoDataset
using a TAdoDataset as property does not work

I actually tried that approach for a few months :)
Didn't work, kept on having errors
Geert GOracle dbaCommented:
i think this is the same problem as you have:

you can also create your own component descending from TAdoQuery
and then hide the properties using a not very well documented function in DesignIntf
add this in a package
and see what you get in the inspector


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.