Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread One variable for TDBISAMTable and TADOTable
Mon, May 28 2012 8:31 AMPermanent Link

Maxim V. Terentiev

Hi,

My app uses dbisam for accessing local database.

But I must implement ability to connect to any custom database and use it as datasource instead of some local dbisam tables.

It's possible to declare one variable (DataModule->MyTable) and change it's type depends on database type ?

I want to keep currently developed and well tested functions who perform db modification unchanged (or add  as small changes as possible).

I can't declare DataModule->MyTable as TDataSet because in this case I lost access to some properties (TableName, IndexDefs) needed in my code.

So, I want to write something like this:

void __fastcall OpenTable(bool LocalMode)
{
if(LocalMode)
   {
   DataModule->MyTable=new TDBISAMTable;
   DataModule->MyTable->TableName="sometable";
   }
else
   {
   DataModule->MyTable=new TADOTable;
   DataModule->MyTable->TableName="someADOtable";
   }
DataModule->MyTable->Open();
}

But don't know what type must be used for MyTable ?

Thanx for help !
Tue, May 29 2012 10:35 AMPermanent Link

Jose Eduardo Helminsky

HPro Informatica

Maxim

The only thing that comes in my mind is compiler directives.
Go to Project menu, options, Compiler options and add a Conditional
directive DBISAM.

{$ifdef DBISAM}
var Table: TDBISamTable;
{$else}
var Table: TAdoTable;
{$endif}
begin
       Table := CreateTableComponent;
       Table.TableName := 'Teste';
       Table.Open;
       ...
end;

{$ifdef DBISAM}
function CreateTableComponent: TDBISamTable;
begin
       Result := TDBISamTable.Create(self);
end;
{$else}
function CreateTableComponent: TAdoTable;
begin
       Result := TAdoTable.Create(self);
end;
{$endif}

Eduardo

Wed, Jun 20 2012 11:31 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Maxim,

<< It's possible to declare one variable (DataModule->MyTable) and change
it's type depends on database type ? >>

Unfortunately, no.

<< I want to keep currently developed and well tested functions who perform
db modification unchanged (or add  as small changes as possible).

I can't declare DataModule->MyTable as TDataSet because in this case I lost
access to some properties (TableName, IndexDefs) needed in my code. >>

This is the basic problem with the TDataSet component - it's too generic for
direct table access, but fine for queries.  You're probably going to have to
resort to a wrapper object/class that handles the differences with a
"dataset type" property.  That's what I had to do with the DataSet Manager
in the Elevate Web Builder IDE, which supports both queries and tables in a
similar manner.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Image