Board index » delphi » tSession problems/questions

tSession problems/questions

My intention was to modify the default session after my program
initialized.  I wanted to be able to set Dbase Table Level to 5 in
program 1 and leave at 7 in the program 2.  I assumed that each progam
would use the default session but that the default session is unique
to each program using BDE.  

The results were strange.  The default Idapi.cfg file had a Dbase
Table Level of 7.  In modifying the default session in program 1 to
reflect a Dbase Table Level of 5, I discovered that if I used
Session.GetDriverParams to inform me of the current table level for
this session that it would read 5 for both programs.  Why ?  Shouldn't
program 2 be seperate (have a seperate default session than program 1)
and be unchanged (still read 7) ?      

I then supposed that all BDE applications must share the default
session (not sure if this is right at all) and decided to create my
own session in program 2 (called 'PMX').  This had exactly the same
results - setting BDE config parameters in one application affected
the BDE parameters in other applications that are running at the time.
I am not saving the config to disk either (remarked out).

Is the default session in one BDE app totally seperate from other BDE
apps ?  If so, this is not what the results I am seeing imply.  Even
after creating a new session in program 2 and leaving program 1 using
the default session the settings changes in one program overrode the
other program.

Any thoughts on what I could be doing wrong or some misconceptions
that I may have ?

This is the code I use to create the session

begin
     PmxSession:= tSession.Create(Application.owner );
     ShowMessage(PmxSession.SessionName);
     PmxSession.SessionName:= 'PMX';
     PmxSession.Open;
end;

Had to add the following for the unit:

type
  MySessionClass = class(TSession);
//  The previous line is necessary to have access to the
ModifyConfigParams method.

var
  Form1: TForm1;
  PMXSession: tSession;

This is the code that I use in one app to initialize BDE and set the
parameters:

Function ConfigureBDESettings: Boolean;
var
     MyList: TStrings;
     DbiRes: dbiResult;
     MyDate: FMTDATE;
     MyNumber: FMTNUMBER;
     sPath: String;
begin
// Initialize the default cfg configuration
     DbiRes := dbiInit(nil);      

// check for errors
     if (DbiRes = DBIERR_NONE) then
     begin
        Result:= True;

        StrPCopy(MyDate.szDateSeparator,'/');                
// Set Date Format
        MyDate.iDateMode := 2;
        MyDate.bFourDigitYear := TRUE;
        MyDate.bYearBiased := TRUE;
        MyDate.bMonthLeadingZero := TRUE;
        MyDate.bDayLeadingZero := TRUE;
        DbiSetDateFormat(MyDate);

        MyNumber.cDecimalSeparator := '.';                  
// Set Number Format
        MyNumber.cThousandSeparator := ' ';
        MyNumber.iDecimalDigits := 2;
        MyNumber.bLeadingZero := TRUE;
        DBiSetNumberFormat(MyNumber);

        PmxSession.ConfigMode := cmPersistent;
        MyList := TStringList.Create;
        try                                            
//  Set Dbase Table Level
           try
              sPath:= '\drivers\dbase\table create';
              MyList.Clear;
              MySessionClass(PMxsession).GetConfigParams(sPath, '',
MyList);
              MyList.Values['LEVEL'] := '5';
              MySessionClass(Pmxsession).ModifyConfigParams(sPath, '',
MyList);
           except on E: Exception do
           begin
                MessageDlg('Error setting BDE Config parameter
"'+sPath+'"' +
                  #10#13#10#13+ e.message, mtError, [mbOK], 0);
                Result:= False;
                Exit;
           end;
           end;

//  Set Dbase Lang Driver
           try    
              sPath:= '\drivers\dbase\init';
              MyList.Clear;
              MySessionClass(Pmxsession).GetConfigParams(sPath, '',
MyList);
              MyList.Values['LANGDRIVER'] := 'dBASE ENU cp437';
              MyList.Values['VERSION'] := '4.0';
              MySessionClass(Pmxsession).ModifyConfigParams(sPath, '',
MyList);
           except on E: Exception do
           begin
                MessageDlg('Error setting BDE Config parameter "' +
sPath + '"' +
                  #10#13#10#13+ e.message, mtError, [mbOK], 0);
                Result:= False;
                Exit;
           end;
           end;

//  Set MsAccess DLL
           try                                            

              sPath:= '\drivers\msaccess\init';
              MyList.Clear;
              MySessionClass(Pmxsession).GetConfigParams(sPath, '',
MyList);
              MyList.Values['LANGDRIVER'] := 'dBASE ENU cp437';
              MySessionClass(Pmxsession).ModifyConfigParams(sPath, '',
MyList);
           except on E: Exception do
           begin
                MessageDlg('Error setting BDE Config parameter "' +
sPath + '"' +
                  #10#13#10#13+ e.message, mtError, [mbOK], 0);
                Result:= False;
                Exit;
           end;
           end;

//  Set Max File Handles
           try  
              sPath:= '\system\init';
              MyList.Clear;
              MySessionClass(Pmxsession).GetConfigParams(sPath, '',
MyList);
              MyList.Values['MAXFILEHANDLES'] := '100';
              MySessionClass(Pmxsession).ModifyConfigParams(sPath, '',
MyList);
           except on E: Exception do
           begin
                MessageDlg('Error setting BDE Config parameter "' +
sPath + '"' +
                  #10#13#10#13+ e.message, mtError, [mbOK], 0);
                Result:= False;
                Exit;
           end;
           end;  

//  Save to disk      
        {  Session.SaveConfigFile;   }  
        finally
          MyList.Free;
        end;
     end
     else
     begin
          Result:= False;
          if (DbiRes = DBIERR_MULTIPLEINIT) then
                  ShowMessage('Illegal: Initializing more than once.')

          else ShowMessage('Error: Cannot initialize BDE.');
          end;
     end;    
     Session.ConfigMode:= cmAll;  
end;

Button code to modify the table level to 7 would be:

procedure TForm1.Button7Click(Sender: TObject);
var MyList: TStrings;
begin
     try
        try
        MyList := TStringList.Create;
        MyList.Clear;
        Pmxsession.GetConfigParams('\drivers\dbase\table create', '',
MyList);
        MyList.Values['LEVEL'] := '7';
        MyList.Values['MDX BLOCK SIZE'] := '1024';
        MyList.Values['MEMO FILE BLOCK SIZE'] := '1024';

MySessionClass(Pmxsession).ModifyConfigParams('\drivers\dbase\table
create', '', MyList);
        except on E: Exception do
        begin
             Showmessage(e.message);
        end;
        end;
     finally
        MyList.Free;
     end;
end;

I appreciate any help you can give me !

Thanks !

Eric Gooden

 

Re:tSession problems/questions


Quote
Eric Gooden (nos...@nospam.com) wrote:

: My intention was to modify the default session after my program
: initialized.  I wanted to be able to set Dbase Table Level to 5 in
: program 1 and leave at 7 in the program 2.  I assumed that each progam
: would use the default session but that the default session is unique
: to each program using BDE.  
<snip>
: Is the default session in one BDE app totally seperate from other BDE
: apps ?  If so, this is not what the results I am seeing imply.  Even
: after creating a new session in program 2 and leaving program 1 using
: the default session the settings changes in one program overrode the
: other program.

I'm no expert, and haven't had to try what you describe, but it sounds
plausible that, if you tell two programs to load the same IDAPI.CFG,
they will share one location in memory, so that configuration changes
effect both programs.  Have you tried saving two different *.CFG files
under two diffrent names, and telling your second progam to begin its
BDE session using the other configuration file?  If it works, it sounds
like a lot less work than what you're doing.

If you haven't already discovered it, there's a wealth of information
on the BDE at http://www.borland.com/devsupport/bde/  Who knows; there
may be something there that will help you.
--
Rick Carter
carte...@email.uc.edu

Re:tSession problems/questions


Richard,

Thank you  for your reply !

I have tried loading in my own .cfg file.  Here is the history:  We
have several products that use BDE.  The end user would sometimes have
problems with the program running correctly.  The reason, it turned
out, was that things were being changed by another vendor.  So,
another Idapi.cfg was loaded on top (during another companies product
installation) of what was already thier default idapi.cfg.  For
instance, we wanted settings for Dbase Table Level and Lang driver,
Access Dll, and maxfilehandles to be certain values.  The other
companies software installation overwrote these default settings and
our programs would no longer work correctly.

So, we started shipping our own BDE config file named Pmx.cfg.  Our
programs loaded this Pmx.cfg when initializing.  This works fine
except in two cases:

1.  When a client has another product that uses BDE (like a Corel
Office product or ADP software) and these other companies products are
loaded first, our products won't load.  The error is BDE Multiple
config error.  The system won't allow multiple cfg files to be loaded
at the same time (at least with the method I tried - to see this
method go to dejanews powersearch page and search for Eric, Gooden,
Table, Level without the commas then at the bottom change Search to
Past and click the Search button again).  The end user gets annoyed
and frequently complains when they have to shut down one app to start
another.

2.  We use an add-on development tool with Delphi which likes to use
the BDE.  What happens, is the tool within the IDE loads the default
BDE config.  Then when I run my program from within the IDE, my
program will not run because it can't load the Pmx.cfg.

My solution for this seemed reasonable, but has turned out to be a
nightmare.  I cannot seem to get the session (the default or a created
instance of tsession) to work the way I would like.  I thought the
session in one program should be entirely seperate from the session in
another.  Even if I loaded the default cfg in all programs, I thought
I should be able to change the in-memory BDE parameters that my
program can see (without affecting other programs).  Isn't this one of
the purposes that tSession is for ?

I'll take a look at that site, Richard.  There has to be a way to do
this.

Eric

On 20 Jan 2001 17:38:58 GMT, carte...@news.ececs.uc.edu (Richard

Quote
Carter) wrote:
>Eric Gooden (nos...@nospam.com) wrote:
>: My intention was to modify the default session after my program
>: initialized.  I wanted to be able to set Dbase Table Level to 5 in
>: program 1 and leave at 7 in the program 2.  I assumed that each progam
>: would use the default session but that the default session is unique
>: to each program using BDE.  
><snip>
>: Is the default session in one BDE app totally seperate from other BDE
>: apps ?  If so, this is not what the results I am seeing imply.  Even
>: after creating a new session in program 2 and leaving program 1 using
>: the default session the settings changes in one program overrode the
>: other program.

>I'm no expert, and haven't had to try what you describe, but it sounds
>plausible that, if you tell two programs to load the same IDAPI.CFG,
>they will share one location in memory, so that configuration changes
>effect both programs.  Have you tried saving two different *.CFG files
>under two diffrent names, and telling your second progam to begin its
>BDE session using the other configuration file?  If it works, it sounds
>like a lot less work than what you're doing.

>If you haven't already discovered it, there's a wealth of information
>on the BDE at http://www.borland.com/devsupport/bde/  Who knows; there
>may be something there that will help you.

Re:tSession problems/questions


Quote
"Eric Gooden" <nos...@nospam.com> wrote in message

news:vfth6tc3ohdt5jc2dkba4k6tekd8031ji6@4ax.com...

If you haven't already, you may want to take a look through the BDE help
file. The page on Configuration Management may prove enlightening. Among
other things, it indicates that the information you are changing is taken
from the registry. AFAIK the BDE entries will be found at
HKLM\Software\Borland\Database Engine. I think that you will find that all
executing programs share the same BDE library that works with the one set of
registry settings.

Typically levels etc. are backwards compatible. Can the problem be solved by
configuring the engine to work with the highest available level/maximum
value?

Other Threads