Switch Between TRemoteDBDatabase and TGenericDatabase

Hi, Wondering if there is a simple way of having both Local and remote database connections in the same exe and easily switch between the two. I know the database name can be changed at the Dataset but when I have hundreds of screens and dynamic queries I was hoping for a simpler solution. Also know I could compile one exe with TRemoteDBDatabase and another one with TGenericDatabase having the same name but the exe would be only remote or only local.
Both TRemoteDBDatabase / TGenericDatabase inherit from TXDatabase, is there a way to make a TXDatabase component and then assign/reassign either TRemoteDBDatabase or TGenericDatabase at runtime?

Currently, no. They both inherit from TXDatabase exactly to make the exchange easy. So you can modify the TXDataset.Database property to either one or another, and your dataset will work normally with a local or remote access without changing anything in the dataset.

No problem, I will add a function to all my forms OnCreate to set the database property of all the TXDataSets. For the Dynamic queries I figure I could replace the hardcoded database name with a function that returns TXDatabase class. like so

function GetDBConnection(IsLocal: Boolean): TXDatabase;
begin
if IsLocal then
Result := DBDataModule.GenericDatabase
else
Result := DBDataModule.RemoteDatabase;
end;

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.