Link to home
Start Free TrialLog in
Avatar of Mamouri
Mamouri

asked on

Connecting new component to multiple Databases!

Hi
I'm working on a helper component for database programs. This component
derived from TComponent and connect to a TTreeView and load a tree structure
into TTreeView. I want my component could work with multiple Databases like
ADO, BDE, Interbase, DBISAM, etc.

What's the best solution for that? If I set my connection property to
TADOConnection then my component could not work with Paradox. If I set my
connection property as TCustomConnection, in the component I want to create
a DataSet and connect to database. then I don't know to create with kind of
DataSet? TADOTable, TTable, TIBTable, TDBISAMTable?

Does somebody know a good soltution?

Regards

SOLUTION
Avatar of atul_parmar
atul_parmar
Flag of India 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
Sorry for my BAD english.
Avatar of Mamouri
Mamouri

ASKER

I could not get your idea completely. do you know a component that used such idea for connectivity?
I agree with atul_parmer, try to keep it abstract at the TTreeview level, and use "TDataset".
and when you need to talk to the treeview do something like this

procedure DoTreeViewThing(dataset: TDataset);
...
if "using paradox table"  then
  DoTreeViewThing( TDataset(Table1) )  // might be (Table1 AS TDataset) ... I forget which :-)
else if "using ado table" then
  DoTreeViewThing( TDataset(ADOTable1) )
... etc

procedure MyComponent.DoTreeViewThing(dataset: TDataset);
begin
    for i := 0 to pred(dataset.fields.count) do ...
...
    newtreenode.caption := dataset.Fields[0].AsString; // could be TTable, TADOTable, TMemoryTable, etc...
end;
Avatar of Mamouri

ASKER

Thank you parmar and TheRealLoki!
Any other idea?
ASKER CERTIFIED SOLUTION
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
Avatar of Mamouri

ASKER

In fact user must only specify the connection. the component itself must create required TTable or TADOTable or TDBISAMTable and work with these components.

Regads
Avatar of Mamouri

ASKER

I must mention the component I'm workin on is not a general component for every projects. This component will use only on one project.
It seems that you didn't get it clearly. Your component will have a property say Dataset and the user will assign the TDataset compitible component to your propert what may be TTable or TADOTable or TDBISAMTable.

so user will create a connection and a table and assign it to your dataset property.

e.g. YourComponent.Dataset := Table1;
Even if it is not generic component, the above said practice is highly flexible and preferable.