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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry for my BAD english.
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.DoTreeViewThin g(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;
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.DoTreeViewThin
begin
for i := 0 to pred(dataset.fields.count)
...
newtreenode.caption := dataset.Fields[0].AsString
end;
ASKER
Thank you parmar and TheRealLoki!
Any other idea?
Any other idea?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Regads
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;
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.