 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Richard Beilby Guest
|
Posted: Fri Oct 10, 2003 10:42 am Post subject: Getting Database Path Information |
|
|
In Delphi how can I get the file path of a database. I can see that
there is a procedure DBIAddAlias that can set a path, but, there does
not seem to be an equivalent that reads it. The user sites, by the way,
will use BDE Admin to maintain the database. I just want to know the
path as ASCII files will also reside in the database directory.
--
Regards,
Richard Beilby.
|
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Fri Oct 10, 2003 12:04 pm Post subject: Re: Getting Database Path Information |
|
|
"Richard Beilby" <R.Beilby (AT) NoSpam (DOT) co.uk> wrote:
| Quote: | In Delphi how can I get the file path of a database.
|
The people of TeamB always know an easier way. Anyway, this is what I have
learned from the Delphi Help about TDatabase.Params:
property Params: TStrings;
Description
Use Params to examine or specify database connection parameters, such as
path name, server name, schema-caching size, language driver, user name, and
password.
Also at Delphi Help you will find that in a TStrings "Call IndexOfName to
locate the first occurrence of a string with the form Name=Value where the
name part is equal to the Name parameter. (...) The strings that make up the
Params property of a database component (TDatabase) have this format as
well."
So what I do is:
var
DatabasePath
begin
DatabasePath := Database1.Params[Database1.Params.IndexOfName('PATH')];
DatabasePath := StringReplace(DatabasePath,'PATH=','',[]);
end;
Bye,
Marcio Ehrlich
|
|
| Back to top |
|
 |
Marcio Ehrlich Guest
|
Posted: Fri Oct 10, 2003 12:18 pm Post subject: Re: Getting Database Path Information |
|
|
"Marcio Ehrlich" <nouser (AT) nouser (DOT) com> wrote:
| Quote: | So what I do is:
var
DatabasePath
|
Obviously I missed the definition:
var
DatabasePath : String;
M.
|
|
| Back to top |
|
 |
Bill Todd Guest
|
Posted: Fri Oct 10, 2003 1:58 pm Post subject: Re: Getting Database Path Information |
|
|
Here are three ways to get the path associated with an alias. No1 is
for permanent BDE aliases only. No2 works on BDE and local aliases and
No3 works with BDE and local aliases as well as with tables with a
hardcoded path, using DBI calls.
function GetDBPath1(AliasName: string): TFileName;
var ParamList: TStringList;
begin
ParamList := TStringList.Create;
with Session do
try
GetAliasParams(AliasName,ParamList);
Result := UpperCase(ParamList.Values['PATH'])+'';
finally
Paramlist.Free;
end;
end;
function GetDBPath2(AliasName: string): TFileName;
var ParamList: TStringList;
i: integer;
begin
ParamList := TStringList.Create;
with Session do
try try
GetAliasParams(AliasName,ParamList);
except
for i:=0 to pred(DatabaseCount) do
if (Databases[i].DatabaseName = AliasName) then
ParamList.Assign(Databases[i].Params);
end;
Result := UpperCase(ParamList.Values['PATH'])+'';
finally
Paramlist.Free;
end;
end;
function GetDBPath3(ATable: TTable): TFileName;
var TblProps: CURProps;
pTblName, pFullName: DBITblName;
begin
with ATable do
begin
AnsiToNative(Locale, TableName, pTblName, 255);
Check(DBIGetCursorProps(Handle, TblProps));
Check(DBIFormFullName(DBHandle,
pTblName,
TblProps.szTableType,
pFullName));
Result := ExtractFilePath(StrPas(pFullName));
end;
end;
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Richard Beilby Guest
|
Posted: Fri Oct 10, 2003 2:18 pm Post subject: Re: Getting Database Path Information |
|
|
Marcio,
Thank you for your help, it is very useful.
--
Regards,
Richard Beilby.
|
|
| Back to top |
|
 |
Richard Beilby Guest
|
Posted: Fri Oct 10, 2003 2:20 pm Post subject: Re: Getting Database Path Information |
|
|
Bill,
Thank you for this information. Rather than create a TDatabase
component, I will use your example 3 and work on the table.
--
Regards,
Richard Beilby.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|