Board index » delphi » How to set MaxFileHandles in code?

How to set MaxFileHandles in code?

Can somebody give me a code snippet that would set the MAXFILEHANDLES to 99,
instead of the default value of 48?  While you're at it, I'd also like to
set the LOCALSHARE to TRUE.  I realized I just need to make and run this
small utility from time to time (other installs from other software
vendors), and that my program that uses the BDE needs to be restarted in
case the settings have been changed.

Also, is there a way to set these values initially (MAXFILEHANDLES =99 and
LocalShare=TRUE) in the InstallShield for Delphi5 for deployment?  I have
Delphi 5 C/S, but I just need to distribute a full BDE install for my
desktop databases.

Thanks.

 

Re:How to set MaxFileHandles in code?


Quote
>  I realized I just need to make and run this
>small utility from time to time (other installs from other software
>vendors), and that my program that uses the BDE needs to be restarted in
>case the settings have been changed.

You use the BDE API method DbiOpenCfgInfoList for both of these

http://www.borland.com/devsupport/bde/bdeapiex/dbiopencfginfolist.html

Quote

>Also, is there a way to set these values initially (MAXFILEHANDLES =99 and
>LocalShare=TRUE) in the InstallShield for Delphi5 for deployment?

InstallShiled uses an Idapi32.cnf file for the default parameters used in a new
install.  You will find this file in the Redist directory of InstallShield
It is just a BDE config file with a different extension.  You can edit it with
BDEAdmin.exe if you specify the full file name.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:How to set MaxFileHandles in code?


Brian Bushay TeamB <BBus...@Nmpls.com> wrote in message
news:389c45a1.48075423@floyd...

Quote
> http://www.borland.com/devsupport/bde/bdeapiex/dbiopencfginfolist.html

My objective here is that at the start of my program, I need to test if the
Local Share is set to true, and if MAXFILEHANDLES is over 98:

Okay, here's the code that I tested, straight from the examples: gives me a
BDE error of $2A06:
happened after it does:   Check(DbiOpenCfgInfoList(nil, dbiREADONLY,
cfgPERSISTENT, StrPCopy(Temp, Path), hCur));
What should I do to correct this?

procedure TForm1.FormCreate(Sender:TObject);
var count:pword;
begin
  ShowMessage(GetConfigParameter('\SYSTEM\INIT\;LOCAL SHARE',Count));
  ShowMessage(GetConfigParameter('\SYSTEM\INIT\;MAXFILEHANDLES',Count));
end;

uses ...., BDE;

function GetConfigParameter(Param: string; Count: pword): string;
var
  hCur: hDBICur;
  rslt: DBIResult;
  Config: CFGDesc;
  Path, Option: string;
  Temp: array[0..255] of char;
begin
  Result := ''; hCur := nil;
  if Count <> nil then
    Count^ := 0;
  try
    if Pos(';', Param) = 0 then
      raise EDatabaseError.Create('Invalid parameter passed to function.
There must ' +
         'be a semi-colon delimited string passed');
    Path := Copy(Param, 0, Pos(';', Param) - 1);
    Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';',
Param));
    Check(DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPERSISTENT, StrPCopy(Temp,
Path), hCur));
    Check(DbiSetToBegin(hCur));
    repeat
      rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @Config, nil);
      if rslt = DBIERR_NONE then
      begin
        if StrPas(Config.szNodeName) = Option then
          Result := Config.szValue;
        if Count <> nil then
          Inc(Count^);
      end
      else
        if rslt <> DBIERR_EOF then
          Check(rslt);
    until rslt <> DBIERR_NONE;
  finally
    if hCur <> nil then
      Check(DbiCloseCursor(hCur));
  end;
end;

Re:How to set MaxFileHandles in code?


Quote
> Okay, here's the code that I tested, straight from the examples: gives me
a
> BDE error of $2A06:
> happened after it does:   Check(DbiOpenCfgInfoList(nil, dbiREADONLY,
> cfgPERSISTENT, StrPCopy(Temp, Path), hCur));
> What should I do to correct this?

I belive You should do like this:

Quote

> procedure TForm1.FormCreate(Sender:TObject);
> var count:pword;
> begin

      Check(DbiInit(nil));
     try
Quote
>   ShowMessage(GetConfigParameter('\SYSTEM\INIT\;LOCAL SHARE',Count));
>   ShowMessage(GetConfigParameter('\SYSTEM\INIT\;MAXFILEHANDLES',Count));

    finally
      Check(DBiExit);
    end;

Quote
> end;

Gert

Re:How to set MaxFileHandles in code?


Thanks,  I didn't know the function to initialize the BDE, and hat was the
first error that was corrected.  Now, the code managed it to go through most
of the GetConfigParameter function, until it gave me another error:
   Access Violation at Address C35B5E58. Read of Address C35B5E58. Process
stopped.

Any idea how to solve this?

Quote
Gert Kello <Gert.Ke...@mail.ee> wrote in message

news:86jo4b$o0v18@bornews.borland.com...
Quote
> I belive You should do like this:

> > procedure TForm1.FormCreate(Sender:TObject);
> > var count:pword;
> > begin
>       Check(DbiInit(nil));
>      try
> >   ShowMessage(GetConfigParameter('\SYSTEM\INIT\;LOCAL SHARE',Count));
> >   ShowMessage(GetConfigParameter('\SYSTEM\INIT\;MAXFILEHANDLES',Count));
>     finally
>       Check(DBiExit);
>     end;
> > end;

> Gert

Re:How to set MaxFileHandles in code?


Brian Bushay TeamB <BBus...@Nmpls.com> wrote in message
news:388e840d.1465012@floyd...

Quote

> >Thanks,  I didn't know the function to initialize the BDE, and hat was
the
> >first error that was corrected.  Now, the code managed it to go through
most
> >of the GetConfigParameter function, until it gave me another error:
> >   Access Violation at Address C35B5E58. Read of Address C35B5E58.
Process
> >stopped.

> Initialize the Count variable.

Thanks, I got it working already.

But for those people browsing this newgroup. Initializing the count
variable, and initializing the BDE made the code work.  A simpler solution
though is to initialize the BDE and not to use the count variable at all.
Just use nil, which I finally adopted like so:

  Check(DbiInit(nil));
  ShowMessage(GetConfigParameter('\SYSTEM\INIT\;LOCAL SHARE',nil));
  ShowMessage(GetConfigParameter('\SYSTEM\INIT\;MAXFILEHANDLES',nil));

And it worked without a glitch.

Re:How to set MaxFileHandles in code?


Quote
>Thanks,  I didn't know the function to initialize the BDE, and hat was the
>first error that was corrected.  Now, the code managed it to go through most
>of the GetConfigParameter function, until it gave me another error:
>   Access Violation at Address C35B5E58. Read of Address C35B5E58. Process
>stopped.

Initialize the Count variable.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads