Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session component ? 1

Status
Not open for further replies.

CentauriAudio

Programmer
Apr 4, 2004
7
AU
I am developing database app with DB tables and BDE. I also want to have an .ini file residing in the database folder, therefore I need to extract the path name from the database alias.

Apparently, this can be done using Session.GetAliasParams(), and from what I have been able to find out, the Session component should exist globally automatically with BDE enabled applications.

However, the compiler compains that 'Session' is undeclared.

Anyone have experience with Session, and can anyone enlighten me as the the resultant format of Session.GetAliasParams() ?

Thanks
Graeme
 
The Session variable is declared in the DBTables unit. So you need to have that in your Uses statement.

DBTables will automatically be included in your Uses statement if your form (or DataModule) has a TQuery or TTable component.

You can get the path of the directory containing your tables by accessing the Directory property. In this example, there is only one database so the directory is of the first and only database.
Code:
Session.Databases[0].Directory;
If the application uses more than one database then you would need to locate the appropriate entry in the list of Databases.

This function returns the path of the directory containing the specified database:
Code:
function TForm1.GetPathOfDatabase(const name: string): string;
var
  n: integer;
begin
  n := Session.DatabaseCount;
  repeat
    dec (n);
  until (n<0) or (Session.Databases[n].DatabaseName = name);
  if n>=0 then
    result := Session.Databases[n].Directory
  else
    result := '';
end;
Note that the comparison is case sensitive when you probably don't require case sensitivity when comparing database names.

Andrew
Hampshire, UK
 
Andrew,

Your advice of where the Session variable is declared gave the clue. I am using a separate data module, and TTable is used there but not in the main form. Once I put the code in the data module, the variable was recognised.

Also thanks to your suggestion of the dirctory property - much easier and works well.

Cheers
Graeme
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top