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