Ver Mensaje Individual
  #1  
Antiguo 01-07-2006
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Reputación: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Modificando parámetros del BDE

Este truco está explicado en "La Cara Oculta de Delphi 4", en el capítulo sobre InstallShield. Pero me han preguntado recientemente cómo se pueden modificar desde programa parámetros arbitrarios del Motor de Datos. Puede que exista un mecanismo más directo, pero yo suelo utilizar las funciones que muestro a continuación:

Código Delphi [-]
function GetBDEInfo(const Path, Param: string): string;
var
  hCur: HDbiCur;
  Desc: CFGDesc;
begin
  Result := '';
  DbiOpenCfgInfoList(nil, dbiReadOnly, cfgPersistent, PChar(Path), hCur);
  try
    while DbiGetNextRecord(hCur, dbiNoLock, @Desc, nil) = DBIERR_NONE do
      if StrIComp(Desc.szNodeName, PChar(Param)) = 0 then
      begin
        Result := StrPas(Desc.szValue);
        Break;
      end;
  finally
    DbiCloseCursor(hCur);
  end;
end;

procedure SetBDEInfo(const Path, Param, Value: string);
var
  hCur: HDbiCur;
  Desc: CFGDesc;
begin
  DbiOpenCfgInfoList(nil, dbiReadWrite, cfgPersistent, PChar(Path), hCur);
  try
    while DbiGetNextRecord(hCur, dbiNoLock, @Desc, nil) = DBIERR_NONE do
      if StrIComp(Desc.szNodeName, PChar(Param)) = 0 then
      begin
        StrCopy(Desc.szValue, PChar(Value));
        DbiModifyRecord(hCur, @Desc, True);
        Break;
      end;
  finally
    DbiCloseCursor(hCur);
  end;
end;

¿Por qué dos parámetros, Path y Param, para estas rutinas? El BDE organiza sus parámetros de configuración en un árbol. Cada rama del árbol puede abrirse como si se tratase de una tabla, y cuando se recorre la "tabla", se obtienen registros con el formato (parámetro; valor). Por ejemplo, para modificar el NET DIR de Paradox, y el parámetro LOCAL SHARE podemos utilizar estas rutinas auxiliares:

Código Delphi [-]
procedure SetLocalShare(const Value: string);
begin
  SetBDEInfo('SYSTEM\INIT', 'LOCAL SHARE', Value);
end;

procedure SetNetDir(const Value: string);
begin
  SetBDEInfo('DRIVERS\PARADOX\INIT', 'NET DIR', Value);
end;
Responder Con Cita