Board index » delphi » Exchanging Advantage And BDE Tables during run-time

Exchanging Advantage And BDE Tables during run-time

Hello,

What I would like to do is the following (in a nutshell) : Depending
if I'm running on a local machine or not, I would like to use BDE's
TTable (if running on a local machine), otherwise use Advantage's
TAdstable.

How ever, I don't want to use a large amount of IF statements all
through my code to figure out if I'm using a TTable or a TAdstable.

Is there a way to have the table I'm using (be it a TTable or a
TAdstable) assigned to a single variable and use it with out having to
figure out what type it is before using it??

Thanks for any help in advance,
Nick

 

Re:Exchanging Advantage And BDE Tables during run-time


I think you're going to have to change the DataSet property of all your
DataSources.  I can't think of a way to do that at run-time without if
statements.

Paul / ColumbuSoft
www.columbusoft.com

Quote
Nick Ring <nr...@NOSPAM.smf.com.au> wrote in message

news:390cccae.6779618@postoffice...
Quote
> Hello,

> What I would like to do is the following (in a nutshell) : Depending
> if I'm running on a local machine or not, I would like to use BDE's
> TTable (if running on a local machine), otherwise use Advantage's
> TAdstable.

> How ever, I don't want to use a large amount of IF statements all
> through my code to figure out if I'm using a TTable or a TAdstable.

> Is there a way to have the table I'm using (be it a TTable or a
> TAdstable) assigned to a single variable and use it with out having to
> figure out what type it is before using it??

> Thanks for any help in advance,
> Nick

Re:Exchanging Advantage And BDE Tables during run-time


Yes, and if you want to store your TTable or TAdstable in a common variable
use type TDataSet.

"Paul Ferrara" <p...@nospam.columbusoft.com> schreef in bericht
news:8ej96l02qr0@news2.newsguy.com...

Quote
> I think you're going to have to change the DataSet property of all your
> DataSources.  I can't think of a way to do that at run-time without if
> statements.

> Paul / ColumbuSoft
> www.columbusoft.com

> Nick Ring <nr...@NOSPAM.smf.com.au> wrote in message
> news:390cccae.6779618@postoffice...
> > Hello,

> > What I would like to do is the following (in a nutshell) : Depending
> > if I'm running on a local machine or not, I would like to use BDE's
> > TTable (if running on a local machine), otherwise use Advantage's
> > TAdstable.

> > How ever, I don't want to use a large amount of IF statements all
> > through my code to figure out if I'm using a TTable or a TAdstable.

> > Is there a way to have the table I'm using (be it a TTable or a
> > TAdstable) assigned to a single variable and use it with out having to
> > figure out what type it is before using it??

> > Thanks for any help in advance,
> > Nick

Re:Exchanging Advantage And BDE Tables during run-time


Quote
"Paul Ferrara" <p...@nospam.columbusoft.com> wrote in message

news:8ej96l02qr0@news2.newsguy.com...

Quote
> I think you're going to have to change the DataSet property of all your
> DataSources.  I can't think of a way to do that at run-time without if
> statements.

I'm not sure about what do to at design time (possibly a tDataSet descendant
whoose constructor redirected the construction to the appropriate
BDE/Advantage constructor), but at run time the following should work.

type tForm1 = class (tForm)
    . . .
    private
        fMyDataSet        : tDataSet;
    . . .
    end;

procedure tForm1.FormCreate (Sender : tObject);

begin
if UsingBDE {you'll have to work this one out}
then begin
    fMyDataSet := tTable.Create (Self);
    {assign SessionName, DatabaseName, TableName and other BDE required
properties}
    end
else begin {assuming only two table types}
    fMyDataSet := tADstable.Create (Self);
    {assign the Advantage required properties}
    end;
{hook the dataset to the datasource}
DataSource1.DataSet := fMyDataSet;
fMyDataSet.Open;
end;

Of course one has to include both the BDE and Advantage db engine in the
release. (Also DBTables and the Advantage equivalent(s) have to be in the
Implementation section Uses clause.) I don't know about Advantage, but
AFAIR, DBTables has an initialization section does some work with sessions
but I can't recall if it ends up starting the BDE or if that only occurs
when the first BDE table is openned.

At design time one might be able to work with a component whoose
construction looked something like:

class function tMyDataSet.NewInstance : tObject;

begin { override so that no memory is allocated }
//
end;

constructor tMyDataSet.Create (anOwner : tComponent);

begin
if UsingBDE
then Self := tMyDataSet (tTable.Create (anOwner))
else Self := tMyDataSet (tADstable.Create (anOwner));
end;

Other than known that this compiles, (and with a very simple test works), I
really don't know all the ramafications of using it. So caution would be
advised.

Quote

> Paul / ColumbuSoft
> www.columbusoft.com

> Nick Ring <nr...@NOSPAM.smf.com.au> wrote in message
> news:390cccae.6779618@postoffice...
> > Hello,

> > What I would like to do is the following (in a nutshell) : Depending
> > if I'm running on a local machine or not, I would like to use BDE's
> > TTable (if running on a local machine), otherwise use Advantage's
> > TAdstable.

> > How ever, I don't want to use a large amount of IF statements all
> > through my code to figure out if I'm using a TTable or a TAdstable.

> > Is there a way to have the table I'm using (be it a TTable or a
> > TAdstable) assigned to a single variable and use it with out having to
> > figure out what type it is before using it??

> > Thanks for any help in advance,
> > Nick

Re:Exchanging Advantage And BDE Tables during run-time


Quote
"Bruce Roberts" <no.junk.please....@attcanada.net> wrote:

>I'm not sure about what do to at design time (possibly a tDataSet descendant
>whoose constructor redirected the construction to the appropriate
>BDE/Advantage constructor), but at run time the following should work.

Well, the code seems to be OK but the original question does not want all the complicated stuff like creating objects and all that.

Quote
>> > Is there a way to have the table I'm using (be it a TTable or a
>> > TAdstable) assigned to a single variable and use it with out having to
>> > figure out what type it is before using it??

As far as the assignement is concerned, you can assign any kind of your variable to anything, as long as you know what are you doing. I've been
assigning "whoknowswhat" to TTable and TQuery. The important thing is that it is a descendant of the TDataSet.

Smola
--
Slowly growing deaf.

Other Threads