Newsgroup: it.comp.lang.delphi
Titolo: [d5] cambiare via codice netdir del bde

ciao a tutti, so che sto ancora stressando con questa cosa, però ho un 
applicazione che deve girare su vista e l'unico modo che ho trovato per 
farla girare è mettere nel netdir di bde c:\miaapplic però il bde per 
default mi mette c:\, come potrei fare per modificarlo durante 
l'installazione da un mio exe fatto ad hoc?
Simone 

ecco la soluzione (su xp funzia, su vista devo provare)
edit1.text contiene il path del netdir
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, 
Dialogs,bde,db,
  Grids, DBGrids, DBTables, StdCtrls;
const
  { Here are the parameters used to pass into the cfg functions.  These are 
only
    a small portion of what types can be passed in.  You need to call
    DbiOpenCfgInfoList with '\' into pszCfgPath to get all possible options 
if
    it is not foend below. }
  { Paradox Driver Settings...  }
  PARADOXNETDIR = '\DRIVERS\PARADOX\INIT\;NET DIR';
  PARADOXVERSION = '\DRIVERS\PARADOX\INIT\;VERSION';
  PARADOXTYPE = '\DRIVERS\PARADOX\INIT\;TYPE';
  PARADOXLANGDRIVER = '\DRIVERS\PARADOX\INIT\;LANGDRIVER';
  PARADOXLEVEL = '\DRIVERS\PARADOX\TABLE CREATE\;LEVEL';
  PARADOXBLOCKSIZE = '\DRIVERS\PARADOX\TABLE CREATE\;BLOCK SIZE';
  PARADOXFILLFACTOR = '\DRIVERS\PARADOX\TABLE CREATE\;FILL FACTOR';
  PARADOXSTRICTINTEGRITY = '\DRIVERS\PARADOX\TABLE CREATE\;STRICTINTEGRITY';
  { dBASE Driver Settings...  }
  DBASEVERSION = '\DRIVERS\DBASE\INIT\;VERSION';
  DBASETYPE = '\DRIVERS\DBASE\INIT\;TYPE';
  DBASELANGDRIVER = '\DRIVERS\DBASE\INIT\;LANGDRIVER';
  DBASELEVEL = '\DRIVERS\DBASE\TABLE CREATE\;LEVEL';
  DBASEMDXBLOCKSIZE = '\DRIVERS\DBASE\TABLE CREATE\;MDX BLOCK SIZE';
  DBASEMEMOFILEBLOCKSIZE = '\DRIVERS\DBASE\TABLE CREATE\;MEMO FILE BLOCK 
SIZE';
  { InterBase Driver Settings...  }
  INTERBASESERVERNAME = '\DRIVERS\INTRBASE\DB OPEN\;SERVER NAME';
  INTERBASEUSERNAME = '\DRIVERS\INTRBASE\DB OPEN\;USER NAME';
  INTERBASEOPENMODE = '\DRIVERS\INTRBASE\DB OPEN\;OPEN MODE';
  INTERBASESCHEMACACHESIZE = '\DRIVERS\INTRBASE\DB OPEN\;SCHEMA CACHE SIZE';
  INTERBASELANGDRIVER = '\DRIVERS\INTRBASE\DB OPEN\;LANGDRIVER';
  INTERBASESQLQRYMODE = '\DRIVERS\INTRBASE\DB OPEN\;SQLQRYMODE';
  INTERBASESQLPASSTHRUMODE = '\DRIVERS\INTRBASE\DB OPEN\;SQLPASSTHRU MODE';
  INTERBASESCHEMACACHETIME = '\DRIVERS\INTRBASE\DB OPEN\;SCHEMS CACHE TIME';
  INTERBASEMAXROWS = '\DRIVERS\INTRBASE\DB OPEN\;MAX ROWS';
  INTERBASEBATCHCOUNT = '\DRIVERS\INTRBASE\DB OPEN\;BATCH COUNT';
  INTERBASEENABLESCHEMACACHE = '\DRIVERS\INTRBASE\DB OPEN\;ENABLE SCHEMA 
CACHE';
  INTERBASEENABLEBCD = '\DRIVERS\INTRBASE\DB OPEN\;ENABLE BCD';
  INTERBASEBLOBSTOCACHE = '\DRIVERS\INTRBASE\DB OPEN\;BLOBS TO CACHE';
  INTERBASEBLOBSIZE = '\DRIVERS\INTRBASE\DB OPEN\;BLOB SIZE';
  INTERBASEVERSION = '\DRIVERS\INTRBASE\INIT\;VERSION';
  INTERBASETYPE = '\DRIVERS\INTRBASE\INIT\;TYPE';
  INTERBASEDLL = '\DRIVERS\INTRBASE\INIT\;DLL';
  INTERBASEDRIVERFLAGS = '\DRIVERS\INTRBASE\INIT\;DRIVER FLAGS';
  INTERBASEDLL32 = '\DRIVERS\INTRBASE\INIT\;DLL32';
  INTERBASETRACEMODE = '\DRIVERS\INTRBASE\INIT\;TRACE MODE';
  { Oracle Driver Settings...  }
  ORACLEBATCHCOUNT = '\DRIVERS\ORACLE\DB OPEN\;BATCH COUNT';
  ORACLEENABLEBCD = '\DRIVERS\ORACLE\DB OPEN\;ENABLE BCD';
  ORACLEENABLEINTEGERS = '\DRIVERS\ORACLE\DB OPEN\;ENABLE INTEGERS';
  ORACLEENABLESCHEMACACHE = '\DRIVERS\ORACLE\DB OPEN\;ENABLE SCHEMA CACHE';
  ORACLELANGDRIVER = '\DRIVERS\ORACLE\DB OPEN\;LANGDRIVER';
  ORACLELISTSYNONYMS = '\DRIVERS\ORACLE\DB OPEN\;LIST SYNONYMS';
  ORACLEMAXROWS = '\DRIVERS\ORACLE\DB OPEN\;MAX ROWS';
  ORACLENETPROTOCOL = '\DRIVERS\ORACLE\DB OPEN\;NET PROTOCOL';
  ORACLEOPENMODE = '\DRIVERS\ORACLE\DB OPEN\;OPENMODE';
  ORACLEROWSETSIZE = '\DRIVERS\ORACLE\DB OPEN\;ROWSET SIZE';
  ORACLESCHEMACACHEDIR = '\DRIVERS\ORACLE\DB OPEN\;SCHEMA CACHE DIR';
  ORACLESCHEMACACHESIZE = '\DRIVERS\ORACLE\DB OPEN\;SCHEMA CACHE SIZE';
  ORACLESCHEMACACHETIME = '\DRIVERS\ORACLE\DB OPEN\;SCHEMA CACHE TIME';
  ORACLESERVERNAME = '\DRIVERS\ORACLE\DB OPEN\;SERVER NAME';
  ORACLESQLPASSTHRUMODE = '\DRIVERS\ORACLE\DB OPEN\;SQLPASSTHRU MODE';
  ORACLESQLQUERYMODE = '\DRIVERS\ORACLE\DB OPEN\;SQLQRYMODE';
  ORACLEUSERNAME = '\DRIVERS\ORACLE\DB OPEN\;USER NAME';
  ORACLEDLL = '\DRIVERS\ORACLE\INIT\;DLL';
  ORACLEDLL32 = '\DRIVERS\ORACLE\INIT\;DLL32';
  ORACLEDRIVERFLAGS = '\DRIVERS\ORACLE\INIT\;DRIVER FLAGS';
  ORACLETRACEMODE = '\DRIVERS\ORACLE\INIT\;TRACE MODE';
  ORACLETYPE = '\DRIVERS\ORACLE\INIT\;TYPE';
  ORACLEVENDORINIT = '\DRIVERS\ORACLE\INIT\;VENDOR INIT';
  ORACLEVERSION = '\DRIVERS\ORACLE\INIT\;VERSION';
  { MSACCESS Driver Settings...  }
  MSACCEESSLANGDRIVER = '\DRIVERS\MSACCESS\DB OPEN\;LANGDRIVER';
  MSACCESSDATABASENAME = '\DRIVERS\MSACCESS\DB OPEN\;DATABASE NAME';
  MSACCESSUSERNAME = '\DRIVERS\MSACCESS\DB OPEN\;USER NAME';
  MSACCESSOPENMODE = '\DRIVERS\MSACCESS\DB OPEN\;OPEN MODE';
  MSACCESSSYSTEMDATABASE = '\DRIVERS\MSACCESS\DB OPEN\;SYSTEMDATABASE';
  MSACCESSVERSION = '\DRIVERS\MSACCESS\INIT\;VERSION';
  MSACCESSTYPE = '\DRIVERS\MSACCESS\INIT\;TYPE';
  MSACCESSDLL32 = '\DRIVERS\MSACCESS\INIT\;DLL32';
  MSACCESSDRIVERFLAGS = '\DRIVERS\MSACCESS\INIT\;DRIVER FLAGS';
  MSACCESSTRACEMODE = '\DRIVERS\MSACCESS\INIT\;TRACE MODE';
  { System Initialization Settings...  }
  AUTOODBC = '\SYSTEM\INIT\;AUTO ODBC';
  DATAREPOSITORY = '\SYSTEM\INIT\;DATA REPOSITORY';
  DEFAULTDRIVER = '\SYSTEM\INIT\;DEFAULT DRIVER';
  LANGDRIVER = '\SYSTEM\INIT\;LANGDRIVER';
  LOCALSHARE = '\SYSTEM\INIT\;LOCAL SHARE';
  LOWMEMORYUSAGELIMIT = '\SYSTEM\INIT\;LOW MEMORY USAGE LIMIT';
  MAXBUFSIZE = '\SYSTEM\INIT\;MAXBUFSIZE';
  MAXFILEHANDLES = '\SYSTEM\INIT\;MAXFILEHANDLES';
  MEMSIZE = '\SYSTEM\INIT\;MEMSIZE';
  MINBUFSIZE = '\SYSTEM\INIT\;MINBUFSIZE';
  SHAREDMEMLOCATION = '\SYSTEM\INIT\;SHAREDMEMLOCATION';
  SHAREDMEMSIZE = '\SYSTEM\INIT\;SHAREDMEMSIZE';
  SQLQRYMODE = '\SYSTEM\INIT\;SQLQRYMODE';
  SYSFLAGS = '\SYSTEM\INIT\;SYSFLAGS';
  VERSION = '\SYSTEM\INIT\;VERSION';
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure SetConfigParameter2(Param: string; Value: string);
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
//SetConfigParameter2(LOCALSHARE, 'TRUE')
procedure TForm1.SetConfigParameter2(Param: string; Value: string);
var
  hCfg: hDBICfg;
  Config: SYSConfig;
  Path, Option: string;
  ParamCount, I: word;
  pFields, pFld: pFLDDesc;
  pRecBuf, pRec: pBYTE;
  Found, SelfInitialized: boolean;
  rslt: DBIResult;
begin
  {$Ifdef WIN32}
  hCfg := nil; pFld := nil; pRec := nil; Found := False; SelfInitialized := 
False;
  try
    if Pos(';', Param) = 0 then
      raise EDatabaseError.Create('Invalid parameter passed to function. 
There must ' +
         'be a semi-colon delimited sting passed');
    Path := Copy(Param, 0, Pos(';', Param) - 1);
    Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';', 
Param));
    rslt := DbiGetSysConfig(Config);
    if rslt <> DBIERR_NONE then
    begin
      if rslt = DBIERR_NOTINITIALIZED  then // Engine not initialized 
error...
      begin
        SelfInitialized := True;
        DbiInit(nil);
        Check(DbiGetSysConfig(Config));
      end
      else
        Check(rslt);
    end;
    (* DbiOpenConfigFile is defined as such:
        function DbiOpenConfigFile (            { Open/Create 
configuration }
              pszDirPath    : PChar;            { Directory }
              bCreate       : Bool;             { TRUE to create/overwrite }
        var   hCfg          : hDBICfg           { Handle to config }
                           ): DBIResult stdcall; *)
    Check(DbiOpenConfigFile(Config.szIniFile, FALSE, hCfg));
    (* DbiCfgGetRecord is defined as such:
        function DbiCfgGetRecord (              { Get a record }
              hCfg          : hDBICfg;          { Config Handle/NULL }
              pszCfgPath    : PChar;            { Path }
        var   iFields       : Word;             { Returned nbr of fields }
              pfldDesc      : pFLDDesc;         { Field descriptors }
              pRec          : Pointer           { Field values }
                           ): DBIResult stdcall; *)
    { Call it without the field and record buffer to get the count... }
    Check(DbiCfgGetRecord(hCfg, PChar(Path), ParamCount, nil, nil));
    pFields := AllocMem(ParamCount * sizeof(FLDDesc));
    pFld := pFields;
    pRecBuf := AllocMem(10000);
    pRec := pRecBuf;
    { Get the node values... }
    Check(DbiCfgGetRecord(hCfg, PChar(Path), ParamCount, pFields, pRecBuf));
    for I := 0 to ParamCount - 1 do
    begin
      if pFields^.szName = Option then
      begin
        StrPCopy(PChar(pRecBuf), Value);
        (* DbiCfgModifyRecord is defines as such:
             function DbiCfgModifyRecord (           { Modify a record }
                   hCfg          : hDBICfg;          { Config Handle/NULL }
                   pszCfgPath    : PChar;            { Path }
                   iFields       : Word;             { Nbr of fields }
                   pfldDesc      : pFLDDesc;         { Field descriptors }
                   pRec          : Pointer           { Data values }
                ): DBIResult stdcall; *)
        Check(DbiCfgModifyRecord(hCfg,  PChar(Path), ParamCount, pFld, 
pRec));
        Found := True;
      end;
      Inc(pFields);
      Inc(pRecBuf, 128);
    end;
    if Found = False then
      raise EDatabaseError.Create(Param + ' entry was not found in 
configuration file');
  finally
    if pFld <> nil then
      FreeMem(pFld);
    if pRec <> nil then
      FreeMem(pRec);
    if hCfg <> nil then
    (* DbiCloseConfigFile is defined as such:
           function DbiCloseConfigFile (           { Close the config file }
           var   hCfg          : hDBICfg;          { Handle }
                 bSave         : Bool;             { To save the changes }
                 bDefault      : Bool;             { To make this file the 
default }
                 bSaveAs16     : Bool              { To save as a 16-bit 
config file }
              ): DBIResult stdcall; *)
      { Close and save the config file... }
    Check(DbiCloseConfigFile(hCfg, TRUE, TRUE, FALSE));
    if SelfInitialized = True then
      DbiExit;
  end;
  {$Else}
     raise EDatabaseError.Create('Non supported function in 16 bit');
  {$EndIf}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
 SetConfigParameter2(PARADOXNETDIR, Edit1.text)
end;
end. 

Simone P. ha scritto:

Perchè invece non lo modifichi a runtime?
Puoi utilizzare un TDatabase e quindi con 
nomeTDatabase.Session.NetFileDir:= "DBPath" modifichi quanto ti serve, 
ovviamente prima di aprire il db.
Se l'applicazione è usata in rete la NetFileDir deve essere la stessa, 
quindi dovrebbe essere UNC; idem per più istanze ma senza obbligo di UNC.
Ci sarebbero anche api a basso livello del BDE ma non ricordo quali 
perchè preferivo non utilizzarle (e ora che non uso piu' BDE so che è 
stata una scelta giusta).
-- 
For a list of all the ways technology has failed to improve the quality 
of life, please press three.
(C) Alice Kahn

Simone P. ha scritto:
<cut>
Ma non l'avevi gia' postato anni fa, questo codice?
Mmmm ... google ....
http://snipurl.com/1jotv
Eggià!
Hai sempre avuto la soluzione sottomano ...
;-)
Ciao!
P.S.: consiglio spassionato: prevedi qunato prima un porting SENZA BDE
delle tue applicazioni. E' una mina vagante pronta ad esplodere ...
-- 
questo articolo e` stato inviato via web dal servizio gratuito 
http://www.newsland.it/news
 segnala gli abusi ad 
ab...@newsland.it

la procedura funziona, però su Vista dopo aver modificato netdir si blocca 
quando salva, non capisco come poterlo modificare, al momento copio 
fisicametne idapi.cfg e sovrascrivo se esistente, però non è una bella 
soluzione
Simo