Get the path of a BDE alias at runtime (Views: 29)
Problem/Question/Abstract: I need to find out the path of a BDE alias from within an application. I would like to auto detect a backup path to the data. Answer: function GetAliasDir(alias: PChar): PChar; var s: TStringList; i: integer; t: string; res: array[0..255] of char; begin res := ''; if Session.IsAlias(alias) then begin {Check if alias exists} s := TStringList.Create; try Session.GetAliasParams(Alias, s); t := ''; if s.count > 0 then begin i := 0; while (i < s.count) and (Copy(s.Strings[i], 1, 5) <> 'PATH=') do inc(i); if (i < s.count) and (Copy(s.Strings[i], 1, 5) = 'PATH =') then begin t := Copy(s.Strings[i], 6, Length(s.Strings[i]) - 4); if t[length(t)] <> '\' then t := t + '\'; end; end; StrPCopy(res, t); except StrPCopy(res, ''); end; s.Free; end; result := res; end; |