José,
Not only can you have multiple databases open at the same time, but you can have multiple copies of the same database open. And you can build database objects that also contain other database objects. See this example:
[url:z2y22mrc]http://forums.fivetechsupport.com/viewtopic.php?f=3&t=34310&sid=7105035b8916154ec3004198fe9c7663&start=15#p203884[/url:z2y22mrc]
One of the advantages of database objects is that you don't have to deal with workspaces and aliases. These are handled automatically. Also you don't need scatter/gather routines--again handled automatically. And code is much easer to read since most of it is hidden.
[code=fw:z2y22mrc][/code:z2y22mrc]
You may be worried about having multiple copies of the same database open at the same time. That was something that we needed to worry about a long time ago because the hardware was so limited. Now we have large amounts of memory and very fast CPUs, so it is not much of a problem.
[quote:z2y22mrc]How can I change the selected TDatabse object?[/quote:z2y22mrc]
There is no selection required. You just reference the object. Simple!
[code=fw:z2y22mrc][/code:z2y22mrc]
The first thing I suggest you do is build a class for each database that you need to use. With coding we should always try to write each bit of code only once. So with database objects you should do the same. So each database class should open the database, it's indexes and set the primary key index to the default. Then instead of doing this each time you open a database:
[code=fw:z2y22mrc][/code:z2y22mrc]
You build a class, that does that, so then you just do:
[code=fw:z2y22mrc][/code:z2y22mrc]
And you can open two copies at the same time like this:
[code=fw:z2y22mrc][/code:z2y22mrc]
Or, you can open two copies of the same database using exactly the same code if they are LOCALs in different functions or classes.
[code=fw:z2y22mrc][/code:z2y22mrc]
An added advantage to isolating the name, source and indexes of the database in a database class will allow you, at a later time, to switch to a new database without changing any of your code except in the New() method of the class for that object. Not just a new DBF, but a new database type like SQL. Wow, encapsulation is very useful!
[quote:z2y22mrc]I think that I'll be able to use the class.[/quote:z2y22mrc]
Not only will you be able to use it, database objects will open a whole new world for you.
James
↧