• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

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 )
  private
     ... some code ...
  published

    property ADOConnection : TADOConnection  read FADOConnection write SetADOConnection;

    property Users: TADODataSet read FUsers ;

  public

    constructor Create( AOwner: TComponent ); override ;

  end;

Open in new window

0
soozh
Asked:
soozh
  • 5
  • 5
  • 3
  • +1
1 Solution
 
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.
0
 
soozhAuthor 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?
0
 
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)
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
soozhAuthor 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?  
0
 
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)
http://www.nldelphi.com/forum/showthread.php?t=30292
this one contains the pro and enterprise version of it
http://www.nldelphi.nl/Forum/showthread.php?t=30292&page=3
0
 
soozhAuthor 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.
0
 
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
0
 
Geert GOracle dbaCommented:
look for RegisterModule in the designer packages
0
 
soozhAuthor 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.
0
 
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 ... ?
0
 
soozhAuthor 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?
0
 
8080_DiverCommented:
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:
const
 
0
 
8080_DiverCommented:
Stupid Loatus Notes posted when I was trying to continue typing! :-(

For instance:
const
  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.
0
 
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
0
 
Geert GOracle dbaCommented:
i think this is the same problem as you have:
http://groups.google.com/group/borland.public.delphi.non-technical/browse_thread/thread/52562340a2ecea58

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

uAdoXQReg.pas
uAdoXQ.pas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 5
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now