The Default property works like this:
- if you set default of a TnxSession to true, all TnxTransContext or TnxDatabase created in the same thread will automatically set their Session property
- if you set default of a TnxTransContext to true, all TnxDatabase instances that are linked to that session will set their TransContext property automatically (it makes that context the default for all TnxDatabase that are attached to that session after wards)
- if you set default of a TnxDatabase to true, all TnxTable / TnxQuery that set their session property will set their database property to the default database for that session
For example do the following in code:
- create a TnxSession
- set Default to true
- Create a TnxTransContext
- set default to true
- create a TnxDatabase
- set default to true
- create a TnxTable
The table will be linked to that Database automatically, the database to that Session and Transcontext and the Transcontext to the Session.
Per thread there is one default Session, per Session there is one default Database and one default Database at any one time. It makes your code a lot easier if you are creating a lot of tables in code and want them all hooked up to the same database... or if you automatically want all your databases to share the same TransContext but
it doesn't just leave any properties to automatic instead. At runtime they are always resolved dynamically; at design time, if you use these default properties the links will be resolved once, the properties are set and after that changing the default has no further function.
The default Session is only applied when a TransContext / Database or Dataset is created in the same thread.
When a Session is assigned to a Database and the Transcontext property is currently nil it checks if there is a default TransContext and sets it.
When a Session is assigned to a Dataset (Table/Query) and the Database property is nil it checks if there is a default Database and sets it.
When you create a new Table it will first check if there is a default Session and assign it, then, because you are assigning a Session, it checks if there is a default Database.
This system will never change an existing assignment, only if a property is nil will it check if there is a default that applies to it.