Board index » delphi » BDE Alias path from Alias name?

BDE Alias path from Alias name?

I've tried out the following code retrieved from the web to get the data
path from the alias name, but in my present application it doesn't work.
Creating some other small application doing nothing else that just using
this code from it's one and only main-form it works fine, but implementing
the code in an existing BDE aware database application it returns a zero
length string result.
- - - - -
uses
  SysUtils,DbiProcs, DBiTypes;

function GetDataBaseDir(const Alias : string): String;
{ Will return the directory of the database given the alias
  (without trailing backslash) }
var
  sp  : PChar;
  Res : pDBDesc;
begin
  try
    New(Res);
    sp := StrAlloc(length(Alias)+1);
    StrPCopy(sp,Alias);
    if DbiGetDatabaseDesc(sp,Res) =  0 then
      Result := StrPas(Res^.szPhyName)
    else
      Result := '';
  finally
    StrDispose(sp);
    Dispose(Res);
  end;
end;
- - - - -
If anyone could help solving what could possibly prevent this code from
working, I would be most pleased.
Thanks
Best regards
Niels

 

Re:BDE Alias path from Alias name?


I've tried another implementation:

function GetDataBaseDir(const Alias: string; var AliasPath: string):
Boolean;
var
  Desc: DBDesc;
begin
  try
    Check(DbiGetDatabaseDesc(PChar(Alias),@Desc));
    AliasPath := StrPas(Desc.szPhyName);
    Result := True;
  except
    Result := False;
  end;
end;

Usage:
  strAliasName := <alias string>;
  if GetDataBaseDir(strAliasName,strDataBaseDir) = False then
    begin
       some procedure ...
    end;

which works fine if the TDatabase in that same unit (a TDataModule) is
connected, but still if it's disconnected the function turns False.
Any idea of what's causing the DbiGetDatabaseDesc to fail?

Thanks
Niels

Re:BDE Alias path from Alias name?


Dear fellows
Sorry for all the fuss.
Now it works - same code ! - and I wonder if it's just a matter of BDE
instability?
Anyone having that same experience?
/Niels

Other Threads