Author: Tomas Rutkauskas
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:
1 function GetAliasDir(alias: PChar): PChar;
2 var3 s: TStringList;
4 i: integer;
5 t: string;
6 res: array[0..255] of char;
7 begin8 res := '';
9 if Session.IsAlias(alias) then10 begin{Check if alias exists}11 s := TStringList.Create;
12 try13 Session.GetAliasParams(Alias, s);
14 t := '';
15 if s.count > 0 then16 begin17 i := 0;
18 while (i < s.count) and (Copy(s.Strings[i], 1, 5) <> 'PATH=') do19 inc(i);
20 if (i < s.count) and (Copy(s.Strings[i], 1, 5) = 'PATH =') then21 begin22 t := Copy(s.Strings[i], 6, Length(s.Strings[i]) - 4);
23 if t[length(t)] <> '\' then24 t := t + '\';
25 end;
26 end;
27 StrPCopy(res, t);
28 except29 StrPCopy(res, '');
30 end;
31 s.Free;
32 end;
33 result := res;
34 end;