Board index » delphi » Getting Alias Name

Getting Alias Name

I need to get the path that is assigned to an alias that I'm using in my
program.  I have a string "LSOT"  assigned as the DatabaseName to all of my
TTable's in my program.  I am writing a procedure that requires me to know
the path that is set for the 'LSOT" alias so that I can move the file and
create another file in it's place.  How do I determine the path that is
assigned to an Alias?

I am using Delphi 3

Thanks,
Jesse

 

Re:Getting Alias Name


Quote
On Wed, 20 May 1998 15:31:54 -0400, "Jesse Castleberry" <D...@iThink.net> wrote:
>I need to get the path that is assigned to an alias that I'm using in my
>program.  I have a string "LSOT"  assigned as the DatabaseName to all of my
>TTable's in my program.  I am writing a procedure that requires me to know
>the path that is set for the 'LSOT" alias so that I can move the file and
>create another file in it's place.  How do I determine the path that is
>assigned to an Alias?

>I am using Delphi 3

There are a number of ways.  I wrote this little routine for D1 a long time
ago, but I've recently tested it with D3 and it seems to work.  Basically, you
pass the name of the alias to the GetAliasPath function show below, and it will
return the actual path for that alias.

//=============================================================================
function GetAliasPath(databaseName: string): string;
//-----------------------------------------------------------------------------
// Get the physical path pointed to by the ALIAS
//-----------------------------------------------------------------------------
var
  pszDir: PChar;
  dirDesc: pDBDesc;
  size: word;
begin
  {init}
  Result := '';
  size := length(DatabaseName)+2;
  {allocate memory}
  GetMem(pszDir, size);
  GetMem(dirDesc, sizeof(DBDesc));
  try
    {convert DatabaseName to null-term. string}
    StrPCopy(pszDir, DatabaseName);
    {get description of alias, if any}
    try
      if (DbiGetDatabaseDesc(pszDir, dirDesc) = 0) then
        result := StrPas(dirDesc^.szPhyName) {there is an alias, so return
path}
      else {if result (i.e. error) is not 0 then error}
        result := DatabaseName;          {assume database is the path}
    except {if an error arrived when trying to get the Alias}
      result := DatabaseName;            {assume database is the path}
      end;
  finally
    {release allocated memory}
    FreeMem(pszDir, size);
    FreeMem(dirDesc, sizeof(DBDesc));
    end;
end;

Hth,
Denis
Aquarius Creations
dsarra...@{*word*104}us.ca
http://www.{*word*104}us.ca/~dsarrazin/Homepage1.html

Re:Getting Alias Name


Try this with p_name='PATH'
function GetAliasPath(AList: TStringList; p_name: string): string;
{supply parameters from getaliasparams and the parameter name that
 you are looking for, return the setting. Uses the location of the
 = sign to determine location of the parameter name and settings}
var
equalpos, kcount, mylength: integer;
param_string, param_name: String;
begin
result:='';
  for kcount:=0 to Alist.Count-1 do
    begin
    param_string:=AList.strings[kcount];
    param_string:=trimRight(param_string);
    equalpos:=pos('=',param_string);
    if equalpos<1 then continue;
    Param_name:=leftstring(param_string,equalpos-1);
    if param_name=p_name then
      begin
       mylength:=length(param_string);
       result:=rightString(param_string,mylength-equalpos);
       exit
      end;
    end;
end;

Quote
Bill Todd (TeamB) wrote:
> See TSession.GetAliasParams in the on-line help.

> --
> Bill

> (TeamB cannot answer questions received via email.)
> (To contact me for any other reason remove nospam from my address)

--
Attorney by Day
Mathematics, Mozart, Delphi
and Family.

Re:Getting Alias Name


On Sun, 24 May 1998 11:38:41 -0500, Gerald Von Korff <vonko...@cloudnet.com>
wrote:

Quote
>Try this with p_name='PATH'
>function GetAliasPath(AList: TStringList; p_name: string): string;
>{supply parameters from getaliasparams and the parameter name that
> you are looking for, return the setting. Uses the location of the
> = sign to determine location of the parameter name and settings}
>var
>equalpos, kcount, mylength: integer;
>param_string, param_name: String;
>begin
>result:='';
>  for kcount:=0 to Alist.Count-1 do
>    begin
>    param_string:=AList.strings[kcount];
>    param_string:=trimRight(param_string);
>    equalpos:=pos('=',param_string);
>    if equalpos<1 then continue;
>    Param_name:=leftstring(param_string,equalpos-1);
>    if param_name=p_name then
>      begin
>       mylength:=length(param_string);
>       result:=rightString(param_string,mylength-equalpos);
>       exit
>      end;
>    end;
>end;

Note that another way of writing the above is this:

function GetAliasPath(databaseName: string): string;
var
  infoList: TStringList;
begin
  infoList := TStringList.Create;
  try
    Session.GetAliasParams(databaseName, infoList);
    result := infoList.Values['PATH'];
  finally  
    infoList.Free;
    end;
end;

This function should return the path for the given alias.  It is definitively a
lot simpler than the solution I originally gave, for which I thank Bill Todd.
It also seems to work better.

-Denis
Aquarius Creations
dsarra...@{*word*104}us.ca
http://www.{*word*104}us.ca/~dsarrazin/Homepage1.html

Other Threads