Cita:
Empezado por maravert
La pregunta es como creo ese alias en la otra computadora utilizando codigo.
|
En el truco 152 de Trucomania tienes cómo crear un Alias temporal desde tu aplicación.
A parte puedes probar éste código:
Código Delphi [-]
procedure AddBDEAlias(sAliasName, sAliasPath, sDBDriver: string);
var
h: hDBISes;
begin
DBIInit(nil);
DBIStartSession('dummy', h, '');
DBIAddAlias(nil, PChar(sAliasName), PChar(sDBDriver),
PChar('PATH:' + sAliasPath), True);
DBICloseSession(h);
DBIExit;
end;
<div align="left"> AddBDEAlias('EQUIPOS', 'C:\Equipos', 'PARADOX');
El código siguiente crea uno Persistente, aunque éste no lo he podido probar...
Código Delphi [-]
uses Windows, SysUtils, DbiProcs, DbiErrs, DBTables;
const
CRLF = #13 + #10;
ERR_ALIASDRIVERNOTFOUND = 'Specified driver doesn''t exist.';
ERR_ALIASALREADYEXISTS = 'The Alias (%s) already exists.' + CRLF +
'Would you like to reconfigure it?';
ERR_ALIASINVALIDPARAM = 'Invalid Alias name.';
ERR_ALIASCLOSEBDE = 'Error closing the BDE.' + CRLF +
'Please close all applications and restart Windows';
ERR_ALIASOPENBDE = 'Error initializing BDE. Cannot create Alias.';
procedure CreateAlias(sAlias, sPath, sDriver: string;
PersistentAlias: Boolean);
var
dbEnv: DbiEnv;
dbRes: DbiResult;
Resp: word;
begin
with dbEnv do
begin
StrPCopy(szWorkDir, sPath);
StrPCopy(szIniFile, '');
bForceLocalInit := True;
StrPCopy(szLang, '');
StrPCopy(szClientName, 'dbClientName');
end;
if DbiInit(@dbEnv) <> DbiERR_NONE then
raise Exception.Create(ERR_ALIASOPENBDE);
if sDriver = 'STANDARD' then
dbRes := DbiAddAlias(nil, pchar(sAlias), nil,
pchar('PATH:' + sPath), PersistentAlias)
else
dbRes := DbiAddAlias(nil, pchar(sAlias), pchar(sDriver),
pchar('PATH:' + sPath), PersistentAlias);
case dbRes of
DbiERR_INVALIDPARAM:
raise Exception.Create(ERR_ALIASINVALIDPARAM);
DbiERR_NAMENOTUNIQUE:
begin
resp := MessageBox(0, pchar(Format(ERR_ALIASALREADYEXISTS, [sAlias])),
'CreateAlias', MB_ICONSTOP + MB_YESNO);
if Resp = ID_YES then
begin
Check(DbiDeleteAlias(nil, pchar(sAlias)));
CreateAlias(sAlias, sPath, sDriver, PersistentAlias);
end;
end;
DbiERR_UNKNOWNDRIVER:
raise Exception.Create(ERR_ALIASDRIVERNOTFOUND);
end;
if DbiExit <> DbiERR_NONE then
raise Exception.Create(ERR_ALIASCLOSEBDE);
end;
|